forked from asdf-vm/asdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasdf.bash
70 lines (65 loc) · 2.15 KB
/
asdf.bash
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
#!/usr/bin/env bash
_asdf() {
local cur
cur=${COMP_WORDS[COMP_CWORD]}
local cmd
cmd=${COMP_WORDS[1]}
local prev
prev=${COMP_WORDS[COMP_CWORD - 1]}
local plugins
plugins=$(asdf plugin-list 2>/dev/null | tr '\n' ' ')
# We can safely ignore warning SC2207 since it warns that it will uses the
# shell's sloppy word splitting and globbing. The possible commands here are
# all single words, and most likely won't contain special chars the shell will
# expand.
COMPREPLY=()
case "$cmd" in
plugin-update)
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "$plugins --all" -- "$cur"))
;;
plugin-remove | current | list | list-all)
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "$plugins" -- "$cur"))
;;
plugin-add)
local available_plugins
available_plugins=$( (asdf plugin-list 2>/dev/null && asdf plugin-list-all 2>/dev/null) | sort | uniq -u)
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "$available_plugins" -- "$cur"))
;;
install)
if [[ "$plugins" == *"$prev"* ]]; then
local versions
versions=$(asdf list-all "$prev" 2>/dev/null)
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "$versions" -- "$cur"))
else
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "$plugins" -- "$cur"))
fi
;;
update)
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "--head" -- "$cur"))
;;
uninstall | where | reshim | local | global | shell)
if [[ "$plugins" == *"$prev"* ]]; then
local versions
versions=$(asdf list "$prev" 2>/dev/null)
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "$versions" -- "$cur"))
else
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "$plugins" -- "$cur"))
fi
;;
*)
local cmds='current global help install list list-all local plugin-add plugin-list plugin-list-all plugin-remove plugin-update reshim shell uninstall update where which '
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "$cmds" -- "$cur"))
;;
esac
return 0
}
complete -F _asdf asdf