-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgshell-completion.bash
More file actions
49 lines (41 loc) · 1.25 KB
/
gshell-completion.bash
File metadata and controls
49 lines (41 loc) · 1.25 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
#!/bin/bash
_gshell_completion() {
local cur prev subcmd
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
subcmd="${COMP_WORDS[1]}"
local subcommands="send get sync run open status help"
# First argument - complete subcommands and help flags
if [ "$COMP_CWORD" -eq 1 ]; then
COMPREPLY=($(compgen -W "$subcommands --help -h" -- "$cur"))
return 0
fi
# Check if -r is already in the command words
local has_r=0
for word in "${COMP_WORDS[@]}"; do
if [ "$word" = "-r" ]; then has_r=1; break; fi
done
case "$subcmd" in
"send"|"get"|"sync")
if [[ "$cur" == -* ]]; then
# build flags list
local flags=""
if [ "$has_r" -eq 0 ]; then flags="$flags -r"; fi
if [ "$subcmd" = "send" ] || [ "$subcmd" = "get" ]; then
flags="$flags -n --dry-run"
fi
COMPREPLY=($(compgen -W "$flags" -- "$cur"))
else
COMPREPLY=($(compgen -f -- "$cur"))
fi
;;
"run")
COMPREPLY=()
;;
*)
COMPREPLY=()
;;
esac
return 0
}
complete -F _gshell_completion gshell