]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/npm/npm.plugin.zsh
initial
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / npm / npm.plugin.zsh
1 (( $+commands[npm] )) && {
2   command rm -f "${ZSH_CACHE_DIR:-$ZSH/cache}/npm_completion"
3
4   _npm_completion() {
5     local si=$IFS
6     compadd -- $(COMP_CWORD=$((CURRENT-1)) \
7                  COMP_LINE=$BUFFER \
8                  COMP_POINT=0 \
9                  npm completion -- "${words[@]}" \
10                  2>/dev/null)
11     IFS=$si
12   }
13   compdef _npm_completion npm
14 }
15
16 # Install dependencies globally
17 alias npmg="npm i -g "
18
19 # npm package names are lowercase
20 # Thus, we've used camelCase for the following aliases:
21
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 "
25
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 "
29
30 # Force npm to fetch remote resources even if a local copy exists on disk.
31 alias npmF='npm i -f'
32
33 # Execute command from node_modules folder based on current directory
34 # i.e npmE gulp
35 alias npmE='PATH="$(npm bin)":"$PATH"'
36
37 # Check which npm modules are outdated
38 alias npmO="npm outdated"
39
40 # Update all the packages listed to the latest version
41 alias npmU="npm update"
42
43 # Check package versions
44 alias npmV="npm -v"
45
46 # List packages
47 alias npmL="npm list"
48
49 # List top-level installed packages
50 alias npmL0="npm ls --depth=0"
51
52 # Run npm start
53 alias npmst="npm start"
54
55 # Run npm test
56 alias npmt="npm test"
57
58 # Run npm scripts
59 alias npmR="npm run"
60
61 # Run npm publish 
62 alias npmP="npm publish"
63
64 # Run npm init
65 alias npmI="npm init"
66
67 # Run npm info
68 alias npmi="npm info"
69
70 # Run npm search
71 alias npmSe="npm search"
72
73 npm_toggle_install_uninstall() {
74   # Look up to the previous 2 history commands
75   local line
76   for line in "$BUFFER" \
77     "${history[$((HISTCMD-1))]}" \
78     "${history[$((HISTCMD-2))]}"
79   do
80     case "$line" in
81       "npm uninstall"*)
82         BUFFER="${line/npm uninstall/npm install}"
83         (( CURSOR = CURSOR + 2 )) # uninstall -> install: 2 chars removed
84         ;;
85       "npm install"*)
86         BUFFER="${line/npm install/npm uninstall}"
87         (( CURSOR = CURSOR + 2 )) # install -> uninstall: 2 chars added
88         ;;
89       "npm un "*)
90         BUFFER="${line/npm un/npm install}"
91         (( CURSOR = CURSOR + 5 )) # un -> install: 5 chars added
92         ;;
93       "npm i "*)
94         BUFFER="${line/npm i/npm uninstall}"
95         (( CURSOR = CURSOR + 8 )) # i -> uninstall: 8 chars added
96         ;;
97       *) continue ;;
98     esac
99     return 0
100   done
101
102   BUFFER="npm install"
103   CURSOR=${#BUFFER}
104 }
105
106 zle -N npm_toggle_install_uninstall
107
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