Adding autocomplete to npm install

Jamis Charles
1 min readMay 27, 2016

--

Originally published at jamischarles.com.

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: https://gist.github.com/jamischarles/1669accda0f057df1769c6c0e932827f

Magic!

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.

--

--

Jamis Charles

UI Engineer at PayPal. @jamischarles — Questions to: Questions? https://github.com/jamischarles/ama -> Thoughts are my own. Blog at https://jamischarles.com.