Last active
July 4, 2016 07:23
-
-
Save jamischarles/017aa0f8811cc962cc7a0f0abba2f48b to your computer and use it in GitHub Desktop.
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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