One little npm productivity trick
I’ve spent my last COVID months working on various node.js projects in different shapes and sizes. One of the first things that really bugged me in the beginning was the lack of out-of-box autocomplete for npm commands while using the shell. Since progress is made by lazy people looking for an easier way to do things, I started searching … how to do that. I found out a few minutes later that npm
has things already figured out for you, but you just need to let your shell know about that.
Hello npm completion
As the documentation already states, completion is just a way of enabling tab-completion for all npm’s actions/sub-actions while using bash
or zsh
. If you type
npm completion
in your favorite shell, you will simply see a few lines of shell code. In the beginning of the generated code you will see 2 examples of how you can make this work between shell/OS restarts:
$ npm completion >> ~/.bashrc (or ~/.zshrc)or$ npm completion > /usr/local/etc/bash_completion.d/npm
The last command’s path may differ depending on your current OS. It might be /etc/bash_completion.d
or /usr/local/etc/bash_completion.d/npm
or any other path depending on the OS flavor . You can find the your local path using find / -name bash_completion.d -type d 2>/dev/null
.
Using any of the above commands while using bash
or zsh
will turn default shell completion from
to
or even
If you wish to better understand how autocomplete works within your shell you can further read