-
Notifications
You must be signed in to change notification settings - Fork 4
/
npm-completion.sh
executable file
·90 lines (69 loc) · 1.93 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
type complete > /dev/null 2> /dev/null
HAS_COMPLETE_FUNC=$?
type compdef > /dev/null 2> /dev/null
HAS_COMPDEF_FUNC=$?
_npm_completion_install() {
DO_DEFAULT=false
COMPREPLY=( $( grep "^$CUR" "$NPM_BIN/npm-completion/npm-package-names/npm-all" 2> /dev/null ) "${COMPREPLY[@]}")
}
_npm_completion_existing_global() {
if [ ! -z $NPM_BIN ]; then
DO_DEFAULT=false
pushd $NPM_BIN >/dev/null
COMPREPLY=( $( ls | grep "^$CUR" 2> /dev/null | sed "s/[^a-zA-Z0-9\-]$//" ) "${COMPREPLY[@]}")
popd >/dev/null
fi
}
_npm_completion_existing_local() {
DO_DEFAULT=false
DIR=$(pwd)
while [ ! -d node_modules -a $(pwd) != "/" ]; do
cd ../
done
if [ -d node_modules ]; then
cd node_modules
COMPREPLY=( $( ls | grep "^$CUR" 2> /dev/null | sed "s/[^a-zA-Z0-9\-]$//" ) "${COMPREPLY[@]}")
fi
cd $DIR
}
_get_npm_completion_package_data() {
DIR=$(pwd)
while [ ! -e package.json -a $(pwd) != "/" ]; do
cd ../
done
if [ -e package.json ]; then
$PATH_TO_NPM_COMPLETION/get-package-data.js $(pwd) $1
fi
cd $DIR
}
_npm_completion_package_data() {
DO_DEFAULT=false
COMPREPLY=($(_get_npm_completion_package_data $1 | grep "^$CUR" 2> /dev/null) "${COMPREPLY[@]}")
}
uname | grep "MINGW[0-9][0-9]_NT" > /dev/null
if [ $? = 0 ]; then
IS_WINDOWS="true"
fi
_npm_completion_setup() {
if [ x${words+set} = xset ]; then
COMP_WORDS=("${words[@]}")
fi
if [ x${CURRENT+set} = xset ]; then
COMP_CWORD=$CURRENT
fi
if [ "$IS_WINDOWS" = "true" ]; then
HOME_DIR=~
NPM_BIN=$HOME_DIR"/AppData/Roaming/npm/node_modules"
else
NPM_BIN="$(which npm)"
while [ -h $NPM_BIN ]; do
NPM_BIN=$(dirname $NPM_BIN)/$(ls -ld -- "$NPM_BIN" | awk '{print $11}')
done
NPM_BIN=$(echo $NPM_BIN | sed 's/[\\\/]npm[\\\/]bin.*//')
fi
COMPREPLY=()
}
. "$PATH_TO_NPM_COMPLETION"/completions/npm.sh
if [ "$INCLUDE_YARN_COMPLETION" != "false" ]; then
. "$PATH_TO_NPM_COMPLETION"/completions/yarn.sh
fi