From 32e2408ad0553fcc3cba5572dae2457699951d43 Mon Sep 17 00:00:00 2001 From: Sander Declerck Date: Mon, 28 Jul 2025 11:00:01 +0200 Subject: [PATCH] Fish: only show warning instead of auto-installing safe-chain --- .../startup-scripts/init-fish.fish | 77 ++++++------------- 1 file changed, 25 insertions(+), 52 deletions(-) diff --git a/src/shell-integration/startup-scripts/init-fish.fish b/src/shell-integration/startup-scripts/init-fish.fish index 3a6c18e..86d7fcc 100644 --- a/src/shell-integration/startup-scripts/init-fish.fish +++ b/src/shell-integration/startup-scripts/init-fish.fish @@ -1,76 +1,49 @@ -function installIfCommandNotFound - set cmd $argv[1] +function printSafeChainWarning + set original_cmd $argv[1] - # Check if the command already exists - if type -q $cmd - return 0 - end + # Fish equivalent of ANSI color codes: yellow background, black text for "Warning:" + set_color -b yellow black + printf "Warning:" + 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 - # Safe-chain requires Node.js 18 or higher - set node_version (node -v | sed 's/v//' | cut -d'.' -f1) - if test $node_version -lt 18 - return 2 - end - - # 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 + # Cyan text for the install command + printf "Install safe-chain by using " + set_color cyan + printf "npm install -g @aikidosec/safe-chain" + set_color normal + printf ".\n" end -function installSafeChain - command npm install -g @aikidosec/safe-chain - - if test $status -ne 0 - return 1 - end - - printf "------\n" -end - -function wrapCommand +function wrapSafeChainCommand set original_cmd $argv[1] set aikido_cmd $argv[2] set cmd_args $argv[3..-1] - installIfCommandNotFound $aikido_cmd - set install_result $status - - if test $install_result -eq 2 - command $original_cmd $cmd_args - else + if type -q $aikido_cmd + # If the aikido command is available, just run it with the provided arguments $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 function npx - wrapCommand "npx" "aikido-npx" $argv + wrapSafeChainCommand "npx" "aikido-npx" $argv end function yarn - wrapCommand "yarn" "aikido-yarn" $argv + wrapSafeChainCommand "yarn" "aikido-yarn" $argv end function pnpm - wrapCommand "pnpm" "aikido-pnpm" $argv + wrapSafeChainCommand "pnpm" "aikido-pnpm" $argv end function pnpx - wrapCommand "pnpx" "aikido-pnpx" $argv + wrapSafeChainCommand "pnpx" "aikido-pnpx" $argv end function npm @@ -81,5 +54,5 @@ function npm return end - wrapCommand "npm" "aikido-npm" $argv + wrapSafeChainCommand "npm" "aikido-npm" $argv end \ No newline at end of file