Skip to content
This repository has been archived by the owner on Apr 7, 2021. It is now read-only.

Commit

Permalink
feat(fallback): by default, only fall back if you have an @ in the name
Browse files Browse the repository at this point in the history
BREAKING CHANGE: auto-fallback will no longer fall back unless there was
an @ sign in the command.
  • Loading branch information
zkat committed Jun 9, 2017
1 parent 6bc06fb commit bea08a0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <shell>`.

Expand Down
14 changes: 11 additions & 3 deletions auto-fallback.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 $?
}`
Expand All @@ -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
Expand Down

0 comments on commit bea08a0

Please sign in to comment.