-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbash_completion
126 lines (106 loc) · 2.01 KB
/
bash_completion
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env bash
if ! type dvm &> /dev/null
then
return
fi
_dvm_has_active_version() {
echo "$PATH" | grep -q "$DVM_DIR/versions"
}
_dvm_add_versions_to_opts() {
if [ ! -d "$DVM_DIR/versions" ]
then
return
fi
if [ -z "$(ls -A "$DVM_DIR/versions")" ]
then
return 0
fi
for path in "$DVM_DIR/versions"/*
do
if [ -f "$path/deno" ]
then
version=${path##*/}
opts="$opts $version"
fi
done
}
_dvm_add_aliases_to_opts() {
if [ ! -d "$DVM_DIR/aliases" ]
then
return
fi
if [ -z "$(ls -A "$DVM_DIR/aliases")" ]
then
return 0
fi
for path in "$DVM_DIR/aliases"/*
do
alias_name=${path##*/}
version=$(cat "$path")
if [ -f "$DVM_DIR/versions/$version/deno" ]
then
opts="$opts $alias_name"
fi
done
}
_dvm_add_options_to_opts() {
if [ "$prev" == "run" ]
then
return
fi
if [[ ${cur} == -* ]]
then
opts="$opts -q --color --no-color --quiet --verbose"
fi
}
_dvm_completion() {
local cur
local prev
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts=""
case "$prev" in
install)
if [[ ${cur} == -* ]]
then
opts="--registry= --skip-validation"
fi
;;
use|uninstall|run|which)
if [ "$prev" = "which" ] && _dvm_has_active_version
then
opts="current"
fi
_dvm_add_versions_to_opts
_dvm_add_aliases_to_opts
;;
unalias)
_dvm_add_aliases_to_opts
;;
doctor)
opts="--fix"
;;
dvm|"$DVM_DIR/dvm.sh")
if [[ ${cur} == -* ]]
then
opts="-h --help --version"
else
opts="alias clean current deactivate doctor help install list list-remote
ls ls-remote run upgrade unalias uninstall use which"
fi
;;
*)
opts=""
;;
esac
_dvm_add_options_to_opts
# shellcheck disable=SC2207
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
}
if [ -n "$ZSH_NAME" ]
then
autoload -U +X compinit && compinit
autoload -U +X bashcompinit && bashcompinit
fi
complete -F _dvm_completion dvm