Auto-completes the npm executables in ZSH
Node.js modules sometimes come with handy executables, available under ./node_modules/.bin
.
One way to access them is by doing (as en example);
$ `npm bin`/the_executable_name
With the following code, to be added in your ZSH configuration, you gain autocomplete for these executables through an npmbin
command.
No more need to hurt your pinky finger going up to those backticks, hooray!
Here's the code
#
# Auto completes the executables located in node_modules/.bin
#
function npmbin () {
PATH=$(npm bin):$PATH $@
}
function _comp_npm () {
_arguments '1: :->command_'
case $state in
command_)
_files -W "$(npm bin)" -/
;;
*)
_files
;;
esac
}
compdef _comp_npm npmbin
Have fun!
Written by Xavier Cambar
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#