-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathautocomplete-cosmos.bash
63 lines (55 loc) · 2.23 KB
/
autocomplete-cosmos.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
_generate_cosmos_completions() {
local cur prev opts program
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
program="${COMP_WORDS[0]}" # Use the program name dynamically
# Identify the command or sub-command being used
local command=""
local subcommand=""
local subsubcommand=""
for ((i=1; i < COMP_CWORD; i++)); do
if [[ "${COMP_WORDS[i]}" != -* ]]; then
if [[ -z "$command" ]]; then
command="${COMP_WORDS[i]}"
else
if [[ -z "$subcommand" ]];then
subcommand="${COMP_WORDS[i]}"
else
subsubcommand="${COMP_WORDS[i]}"
break
fi
fi
fi
done
# Fetch and parse options based on the current context
if [[ -n "$subsubcommand" ]]; then
opts="$("${program}" $command $subcommand $subsubcommand --help 2>/dev/null | awk '/Commands:/,/^$/ {if (!/:/ && !/^$/ && $1) print $1}')"
opts+=" $("${program}" $command $subcommand $subsubcommand --help 2>/dev/null | grep -oE '\-\-[a-zA-Z0-9\-]+' | sort -u)"
elif [[ -n "$subcommand" ]]; then
opts="$("${program}" $command $subcommand --help 2>/dev/null | awk '/Commands:/,/^$/ {if (!/:/ && !/^$/ && $1) print $1}')"
opts+=" $("${program}" $command $subcommand --help 2>/dev/null | grep -oE '\-\-[a-zA-Z0-9\-]+' | sort -u)"
elif [[ -n "$command" ]]; then
opts="$("${program}" $command --help 2>/dev/null | awk '/Commands:/,/^$/ {if (!/:/ && !/^$/ && $1) print $1}')"
opts+=" $("${program}" $command --help 2>/dev/null | grep -oE '\-\-[a-zA-Z0-9\-]+' | sort -u)"
else
opts="$("${program}" --help 2>/dev/null | awk '/Commands:/,/^$/ {if (!/:/ && !/^$/ && $1) print $1}')"
opts+=" $("${program}" --help 2>/dev/null | grep -oE '\-\-[a-zA-Z0-9\-]+' | sort -u)"
fi
# Remove duplicate options
opts=$(echo "$opts" | tr ' ' '\n' | awk '!seen[$0]++' | tr '\n' ' ')
# Complete based on the current word
COMPREPLY=($(compgen -W "${opts}" -- "${cur}"))
}
names=(
namada
namadaw
namadan
namadac
entagled
osmosisd
lavad
sided
)
for i in "${names[@]}"; do
complete -F _generate_cosmos_completions "$i"
done