Fish: only show warning instead of auto-installing safe-chain

This commit is contained in:
Sander Declerck 2025-07-28 11:00:01 +02:00
parent 6a8d56dfec
commit 32e2408ad0
No known key found for this signature in database

View file

@ -1,76 +1,49 @@
function installIfCommandNotFound function printSafeChainWarning
set cmd $argv[1] set original_cmd $argv[1]
# Check if the command already exists # Fish equivalent of ANSI color codes: yellow background, black text for "Warning:"
if type -q $cmd set_color -b yellow black
return 0 printf "Warning:"
end set_color normal
printf " safe-chain is not available to protect you from installing malware. %s will be run directly.\n" $original_cmd
# Check if Node.js version is below 18 # Cyan text for the install command
# Safe-chain requires Node.js 18 or higher printf "Install safe-chain by using "
set node_version (node -v | sed 's/v//' | cut -d'.' -f1) set_color cyan
if test $node_version -lt 18 printf "npm install -g @aikidosec/safe-chain"
return 2 set_color normal
end printf ".\n"
# Command not found, ask user if they want to install safe-chain
read -l response -P "The command '$cmd' is not available. Do you want to install safe-chain to provide it? (y/N): "
if string match -qi 'y*' $response
printf "Installing safe-chain...\n"
installSafeChain
if test $status -ne 0
printf "\nFailed to install safe-chain. Exiting.\n"
return 1
end
return 0
else
printf "Skipping safe-chain installation. Using original command instead.\n"
return 2
end
end end
function installSafeChain function wrapSafeChainCommand
command npm install -g @aikidosec/safe-chain
if test $status -ne 0
return 1
end
printf "------\n"
end
function wrapCommand
set original_cmd $argv[1] set original_cmd $argv[1]
set aikido_cmd $argv[2] set aikido_cmd $argv[2]
set cmd_args $argv[3..-1] set cmd_args $argv[3..-1]
installIfCommandNotFound $aikido_cmd if type -q $aikido_cmd
set install_result $status # If the aikido command is available, just run it with the provided arguments
if test $install_result -eq 2
command $original_cmd $cmd_args
else
$aikido_cmd $cmd_args $aikido_cmd $cmd_args
else
# If the aikido command is not available, print a warning and run the original command
printSafeChainWarning $original_cmd
command $original_cmd $cmd_args
end end
end end
function npx function npx
wrapCommand "npx" "aikido-npx" $argv wrapSafeChainCommand "npx" "aikido-npx" $argv
end end
function yarn function yarn
wrapCommand "yarn" "aikido-yarn" $argv wrapSafeChainCommand "yarn" "aikido-yarn" $argv
end end
function pnpm function pnpm
wrapCommand "pnpm" "aikido-pnpm" $argv wrapSafeChainCommand "pnpm" "aikido-pnpm" $argv
end end
function pnpx function pnpx
wrapCommand "pnpx" "aikido-pnpx" $argv wrapSafeChainCommand "pnpx" "aikido-pnpx" $argv
end end
function npm function npm
@ -81,5 +54,5 @@ function npm
return return
end end
wrapCommand "npm" "aikido-npm" $argv wrapSafeChainCommand "npm" "aikido-npm" $argv
end end