Skip to content

Instantly share code, notes, and snippets.

@orzFly
Last active August 29, 2015 14:21
Show Gist options
  • Save orzFly/dd4e7675f69df45c7e23 to your computer and use it in GitHub Desktop.
Save orzFly/dd4e7675f69df45c7e23 to your computer and use it in GitHub Desktop.
NB: npm bin wrapper for zsh
#!/usr/bin/env zsh
nb() {
local npmbin="`npm bin`"
if [ ! -d "$npmbin" ]; then
echo "NB is not available at $npmbin"
return 1
fi
local command="$1"
builtin shift 1
"$npmbin/$command" $*
}
_nb() {
_arguments -C \
'1: :->cmds' \
'*:: :->args' && ret=0
case $state in
cmds)
local npmbin="`npm bin`"
if [ ! -d "$npmbin" ]; then
return 1
fi
_path_files -W "$npmbin"
ret=0
;;
args)
_normal && ret=0
;;
esac
return ret
}
compdef _nb nb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment