forked from ghosind/dvm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bash_completion
92 lines (79 loc) · 1.51 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
#!/usr/bin/env bash
if ! type dvm &> /dev/null
then
return
fi
add_versions_to_opts() {
if [ ! -d "$DVM_DIR/versions" ]
then
return
fi
for path in "$DVM_DIR/versions"/*
do
if [ -f "$path/deno" ]
then
version=${path##*/}
opts="$opts $version"
fi
done
}
add_aliases_to_opts() {
if [ ! -d "$DVM_DIR/aliases" ]
then
return
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_completion() {
local cur
local prev
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
case "$prev" in
use|uninstall|run|which)
if [ "$prev" = "which" ] && [ -f "$DVM_BIN/deno" ]
then
opts="current"
fi
add_versions_to_opts
add_aliases_to_opts
;;
unalias)
add_aliases_to_opts
;;
doctor)
opts="--fix"
;;
dvm|"$DVM_DIR/dvm.sh")
if [[ ${cur} == -* ]]
then
opts="--help --version -h"
else
opts="alias clean current doctor help install list list-remote
ls ls-remote run upgrade unalias uninstall use which"
fi
;;
*)
opts=""
;;
esac
# shellcheck disable=SC2207
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
}
if [ -n "$ZSH_NAME" ]
then
autoload -U +X compinit && compinit
autoload -U +X bashcompinit && bashcompinit
complete -F _dvm_completion "$DVM_DIR/dvm.sh"
else
complete -F _dvm_completion dvm
fi