Adding autocomplete to npm install

Every time I have to type this without autocomplete I get really annoyed:

$ npm install some-really-really-long-package-name

I spent a few hours last night and figured it out.

Adding autocomplete

Solutions below are for bash / zsh only (not Windows, sorry).

If you don’t use npm autocompletion yet, add this snippet to your ~/.bashrc:

If you use zsh, add this to ~/.zshrc.

If you already use npm autocompletion, replace your version with this one:


How it works

We run `ls ~/.npm` and pass all the results as options to bash/zsh autocompletion for the `npm install` command. ~/.npm is the location of the npm cache. This should contain any packages you’ve installed at some point (Not all of npm.).

Questions, comments, feedback? I’m a bash newb, so any improvements are welcome.