Adding autocomplete to npm install

Image for post
Image for post

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

Image for post
Image for post
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.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store