Skip to content
Newer
Older
100644 43 lines (40 sloc) 1.35 KB
cef89a2 @isaacs Initial bash completion support. Very rudimentary.
isaacs authored
1 #
2 # npm command completion script
3 #
4 # Install Method 1: Automatic
18b95cf @isaacs Add COMP environment vars. Log to npm-completion.log
isaacs authored
5 # Put this file in /etc/bash-completion.d or /usr/local/etc/bash-completion.d
cef89a2 @isaacs Initial bash completion support. Very rudimentary.
isaacs authored
6 # or wherever bash-completion scripts are sourced on your system.
7 #
8 # Install Method 2: Generic
18b95cf @isaacs Add COMP environment vars. Log to npm-completion.log
isaacs authored
9 # Put this in .bashrc or whatever file you run when you log into a machine:
cef89a2 @isaacs Initial bash completion support. Very rudimentary.
isaacs authored
10 # . path/to/npm-completion.sh
11 #
18b95cf @isaacs Add COMP environment vars. Log to npm-completion.log
isaacs authored
12 # Then use the tab key, which executes the "npm completion" command.
cef89a2 @isaacs Initial bash completion support. Very rudimentary.
isaacs authored
13 #
18b95cf @isaacs Add COMP environment vars. Log to npm-completion.log
isaacs authored
14 # Special thanks to Evan Meagher for making the npm completion command
15 # much more useful and complete.
cef89a2 @isaacs Initial bash completion support. Very rudimentary.
isaacs authored
16
432245b @isaacs more canonical bash export style
isaacs authored
17 COMP_WORDBREAKS=${COMP_WORDBREAKS/=/}
18 COMP_WORDBREAKS=${COMP_WORDBREAKS/@/}
19 export COMP_WORDBREAKS
cef89a2 @isaacs Initial bash completion support. Very rudimentary.
isaacs authored
20 __npm_completion () {
21 COMPREPLY=()
0ceb449 @isaacs Dump logs to a temp file, and only if requested.
isaacs authored
22 local cur prev opts logfile
23 if [ "${loglevel:-silent}" == "silent" ]; then
24 logfile=/dev/null
25 else
26 logfile=/tmp/npm-completion.log
27 fi
cef89a2 @isaacs Initial bash completion support. Very rudimentary.
isaacs authored
28 cur="${COMP_WORDS[COMP_CWORD]}"
29 prev="${COMP_WORDS[COMP_CWORD-1]}"
30 # opts=$(npm complete --loglevel silent --color false -- "$cur")
18b95cf @isaacs Add COMP environment vars. Log to npm-completion.log
isaacs authored
31 COMPREPLY=( $(COMP_CWORD=$COMP_CWORD \
32 COMP_LINE=$COMP_LINE \
33 COMP_POINT=$COMP_POINT \
34 COMP_WORDBREAKS=$COMP_WORDBREAKS \
35 COMP_WORDS="${COMP_WORDS[@]}" \
0ceb449 @isaacs Dump logs to a temp file, and only if requested.
isaacs authored
36 npm completion --color false --loglevel "${loglevel:-silent}" \
18b95cf @isaacs Add COMP environment vars. Log to npm-completion.log
isaacs authored
37 -- "${COMP_WORDS[@]}" \
0ceb449 @isaacs Dump logs to a temp file, and only if requested.
isaacs authored
38 2>>$logfile ) )
cef89a2 @isaacs Initial bash completion support. Very rudimentary.
isaacs authored
39 return $?
40 }
41
af2dcd6 @isaacs Remove the -o nospace, since it's stupid.
isaacs authored
42 complete -o default -F __npm_completion npm
Something went wrong with that request. Please try again.