-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbash_completion
More file actions
85 lines (73 loc) · 1.92 KB
/
bash_completion
File metadata and controls
85 lines (73 loc) · 1.92 KB
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
#!/usr/bin/env bash
# bash/zsh completion for HarmonyOS Version Manager (hmvm)
if ! type hmvm &> /dev/null; then
return
fi
__hmvm_generate_completion() {
declare current_word
current_word="${COMP_WORDS[COMP_CWORD]}"
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "$1" -- "${current_word}"))
return 0
}
__hmvm_commands() {
declare current_word
current_word="${COMP_WORDS[COMP_CWORD]}"
COMMANDS='help install use ls list ls-remote current uninstall alias which'
case "${current_word}" in
-*) __hmvm_generate_completion '--save -w' ;;
*) __hmvm_generate_completion "${COMMANDS}" ;;
esac
}
__hmvm_installed_versions() {
local HMVM_DIR
HMVM_DIR="${HMVM_DIR:-${HOME}/.hmvm}"
local VERSION_DIR
VERSION_DIR="${HMVM_DIR}/versions/clt"
local versions
if [ -d "${VERSION_DIR}" ]; then
versions="$(command ls -1 "${VERSION_DIR}" 2>/dev/null | command sed 's/^v//' | command tr '\n' ' ')"
fi
__hmvm_generate_completion "${versions:-}"
}
__hmvm_aliases() {
local HMVM_DIR
HMVM_DIR="${HMVM_DIR:-${HOME}/.hmvm}"
local ALIAS_DIR
ALIAS_DIR="${HMVM_DIR}/alias"
local aliases
aliases=""
if [ -d "${ALIAS_DIR}" ]; then
aliases="$(command ls -1 "${ALIAS_DIR}" 2>/dev/null | command tr '\n' ' ')"
fi
__hmvm_generate_completion "${aliases:-} default stable"
}
__hmvm() {
declare previous_word
previous_word="${COMP_WORDS[COMP_CWORD - 1]}"
case "${previous_word}" in
use|uninstall) __hmvm_installed_versions ;;
alias)
if [ "${COMP_CWORD}" -eq 2 ]; then
__hmvm_aliases
else
__hmvm_installed_versions
fi
;;
install)
__hmvm_installed_versions
;;
*)
__hmvm_commands
;;
esac
return 0
}
# ZSH compatibility
if [[ -n ${ZSH_VERSION-} ]]; then
if ! command -v compinit > /dev/null 2>&1; then
autoload -U +X compinit && compinit
fi
autoload -U +X bashcompinit && bashcompinit
fi
complete -o default -F __hmvm hmvm