1
|
###-begin-npm-completion-###
|
2
|
#
|
3
|
# npm command completion script
|
4
|
#
|
5
|
# Installation: npm completion >> ~/.bashrc (or ~/.zshrc)
|
6
|
# Or, maybe: npm completion > /usr/local/etc/bash_completion.d/npm
|
7
|
#
|
8
|
|
9
|
COMP_WORDBREAKS=${COMP_WORDBREAKS/=/}
|
10
|
COMP_WORDBREAKS=${COMP_WORDBREAKS/@/}
|
11
|
export COMP_WORDBREAKS
|
12
|
|
13
|
if type complete &>/dev/null; then
|
14
|
_npm_completion () {
|
15
|
local si="$IFS"
|
16
|
IFS=$'\n' COMPREPLY=($(COMP_CWORD="$COMP_CWORD" \
|
17
|
COMP_LINE="$COMP_LINE" \
|
18
|
COMP_POINT="$COMP_POINT" \
|
19
|
npm completion -- "${COMP_WORDS[@]}" \
|
20
|
2>/dev/null)) || return $?
|
21
|
IFS="$si"
|
22
|
}
|
23
|
complete -F _npm_completion npm
|
24
|
elif type compdef &>/dev/null; then
|
25
|
_npm_completion() {
|
26
|
si=$IFS
|
27
|
compadd -- $(COMP_CWORD=$((CURRENT-1)) \
|
28
|
COMP_LINE=$BUFFER \
|
29
|
COMP_POINT=0 \
|
30
|
npm completion -- "${words[@]}" \
|
31
|
2>/dev/null)
|
32
|
IFS=$si
|
33
|
}
|
34
|
compdef _npm_completion npm
|
35
|
elif type compctl &>/dev/null; then
|
36
|
_npm_completion () {
|
37
|
local cword line point words si
|
38
|
read -Ac words
|
39
|
read -cn cword
|
40
|
let cword-=1
|
41
|
read -l line
|
42
|
read -ln point
|
43
|
si="$IFS"
|
44
|
IFS=$'\n' reply=($(COMP_CWORD="$cword" \
|
45
|
COMP_LINE="$line" \
|
46
|
COMP_POINT="$point" \
|
47
|
npm completion -- "${words[@]}" \
|
48
|
2>/dev/null)) || return $?
|
49
|
IFS="$si"
|
50
|
}
|
51
|
compctl -K _npm_completion npm
|
52
|
fi
|
53
|
###-end-npm-completion-###
|