-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnpm-completion.sh
42 lines (40 loc) · 1.35 KB
/
npm-completion.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#
# npm command completion script
#
# Install Method 1: Automatic
# Put this file in /etc/bash-completion.d or /usr/local/etc/bash-completion.d
# or wherever bash-completion scripts are sourced on your system.
#
# Install Method 2: Generic
# Put this in .bashrc or whatever file you run when you log into a machine:
# . path/to/npm-completion.sh
#
# Then use the tab key, which executes the "npm completion" command.
#
# Special thanks to Evan Meagher for making the npm completion command
# much more useful and complete.
COMP_WORDBREAKS=${COMP_WORDBREAKS/=/}
COMP_WORDBREAKS=${COMP_WORDBREAKS/@/}
export COMP_WORDBREAKS
__npm_completion () {
COMPREPLY=()
local cur prev opts logfile
if [ "${loglevel:-silent}" == "silent" ]; then
logfile=/dev/null
else
logfile=/tmp/npm-completion.log
fi
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
# opts=$(npm complete --loglevel silent --color false -- "$cur")
COMPREPLY=( $(COMP_CWORD=$COMP_CWORD \
COMP_LINE=$COMP_LINE \
COMP_POINT=$COMP_POINT \
COMP_WORDBREAKS=$COMP_WORDBREAKS \
COMP_WORDS="${COMP_WORDS[@]}" \
npm completion --color false --loglevel "${loglevel:-silent}" \
-- "${COMP_WORDS[@]}" \
2>>$logfile ) )
return $?
}
complete -o default -F __npm_completion npm