Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
npm install autocompletion for bash & zsh. Provides content of `~/.npm` as autocomplete options for `npm install` https://medium.com/@jamischarles/adding-autocomplete-to-npm-install-5efd3c424067#.8w0jzkh3w
#!/usr/bin/env zsh #adding this to force silly gist highlighting. REMOVE THIS
# 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
You can’t perform that action at this time.