Skip to content

Instantly share code, notes, and snippets.

@dantailby
Last active June 20, 2016 07:59
Show Gist options
  • Save dantailby/ae35bddfd60a2feabd03c1c838285264 to your computer and use it in GitHub Desktop.
Save dantailby/ae35bddfd60a2feabd03c1c838285264 to your computer and use it in GitHub Desktop.
.zsh npm autocompletion
# ZSH standalone npm install autocompletion. Add this to ~/.zshrc file.
_npm_install_completion() {
local si=$IFS
# if 'install' or 'i ' is one of the subcommands, then...
if [[ ${words} =~ 'install' ]] || [[ ${words} =~ 'i ' ]]; then
# add the result of `ls ~/.npm` (npm cache) as completion options
compadd -- $(COMP_CWORD=$((CURRENT-1)) \
COMP_LINE=$BUFFER \
COMP_POINT=0 \
ls ~/.npm -- "${words[@]}" \
2>/dev/null)
fi
IFS=$si
}
compdef _npm_install_completion 'npm'
## END ZSH npm install autocompletion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment