diff --git a/README.md b/README.md index c2ae25b..ea29659 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,17 @@ $ npx -p lolcatjs -p cowsay -c \ ## SHELL AUTO FALLBACK -You can configure `npx` to run as your default fallback command when you type something in the command line but the command is not found. This includes installing packages that were not found in the local prefix either. +You can configure `npx` to run as your default fallback command when you type something in the command line with an `@` but the command is not found. This includes installing packages that were not found in the local prefix either. + +For example: + +``` +$ npm@4 --version +(stderr) npm@4 not found. Trying with npx... +4.6.1 +$ asdfasdfasf +zsh: command not found: asfdasdfasdf +``` Currently, `zsh`, `bash`, and `fish` are supported. You can access these completion scripts using `npx --shell-auto-fallback `. diff --git a/auto-fallback.js b/auto-fallback.js index 56932f2..3c12870 100644 --- a/auto-fallback.js +++ b/auto-fallback.js @@ -5,11 +5,15 @@ function mkPosix (opts) { command_not_found_${opts.isBash ? 'handle' : 'handler'}() { # Do not run within a pipe if test ! -t 1; then - echo "command not found: $1" + >&2 echo "command not found: $1" + return 127 + fi + if ! [[ $1 =~ @ ]]; then + >&2 echo "command not found: $1" return 127 fi - echo "Trying with npx..." + echo "$1 not found. Trying with npx..." >&2 npx ${opts.install ? '' : '--no-install '}$* return $? }` @@ -22,7 +26,11 @@ function __fish_command_not_found_on_interactive --on-event fish_prompt functions --erase __fish_command_not_found_setup function __fish_command_not_found_handler --on-event fish_command_not_found - echo "Trying with npx..." + if string match -q -v -r @ $argv[1] + echo "fish: Unknown command '$argv[1]'" + return 127 + end + echo "$argv[1] not found. Trying with npx..." >&2 npx ${opts.install ? '' : '--no-install '}$argv end