1 (( $+commands[npm] )) && {
2 command rm -f "${ZSH_CACHE_DIR:-$ZSH/cache}/npm_completion"
6 compadd -- $(COMP_CWORD=$((CURRENT-1)) \
9 npm completion -- "${words[@]}" \
13 compdef _npm_completion npm
16 # Install dependencies globally
17 alias npmg="npm i -g "
19 # npm package names are lowercase
20 # Thus, we've used camelCase for the following aliases:
22 # Install and save to dependencies in your package.json
23 # npms is used by https://www.npmjs.com/package/npms
24 alias npmS="npm i -S "
26 # Install and save to dev-dependencies in your package.json
27 # npmd is used by https://github.com/dominictarr/npmd
28 alias npmD="npm i -D "
30 # Force npm to fetch remote resources even if a local copy exists on disk.
33 # Execute command from node_modules folder based on current directory
35 alias npmE='PATH="$(npm bin)":"$PATH"'
37 # Check which npm modules are outdated
38 alias npmO="npm outdated"
40 # Update all the packages listed to the latest version
41 alias npmU="npm update"
43 # Check package versions
49 # List top-level installed packages
50 alias npmL0="npm ls --depth=0"
53 alias npmst="npm start"
62 alias npmP="npm publish"
71 alias npmSe="npm search"
73 npm_toggle_install_uninstall() {
74 # Look up to the previous 2 history commands
76 for line in "$BUFFER" \
77 "${history[$((HISTCMD-1))]}" \
78 "${history[$((HISTCMD-2))]}"
82 BUFFER="${line/npm uninstall/npm install}"
83 (( CURSOR = CURSOR + 2 )) # uninstall -> install: 2 chars removed
86 BUFFER="${line/npm install/npm uninstall}"
87 (( CURSOR = CURSOR + 2 )) # install -> uninstall: 2 chars added
90 BUFFER="${line/npm un/npm install}"
91 (( CURSOR = CURSOR + 5 )) # un -> install: 5 chars added
94 BUFFER="${line/npm i/npm uninstall}"
95 (( CURSOR = CURSOR + 8 )) # i -> uninstall: 8 chars added
106 zle -N npm_toggle_install_uninstall
108 # Defined shortcut keys: [F2] [F2]
109 bindkey -M emacs '^[OQ^[OQ' npm_toggle_install_uninstall
110 bindkey -M vicmd '^[OQ^[OQ' npm_toggle_install_uninstall
111 bindkey -M viins '^[OQ^[OQ' npm_toggle_install_uninstall