blob: fea45945381779d3ba60e80d7fb0cfb0913e0e92 (
plain)
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
|
# Bash completion script for footclient
_footclient()
{
COMPREPLY=()
local cur prev flags word commands match previous_words i offset
flags=(
"--app-id"
"--fullscreen"
"--help"
"--hold"
"--login-shell"
"--log-level"
"--log-colorize"
"--maximized"
"--override"
"--server-socket"
"--term"
"--title"
"--version"
"--window-size-pixels"
"--window-size-chars"
"--working-directory"
)
flags="${flags[@]}"
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
# check if positional argument is completed
previous_words=( "${COMP_WORDS[@]}" )
unset previous_words[-1]
commands=$(compgen -c | grep -vFx "$(compgen -k)" | grep -vE '^([.:[]|footclient)$' | sort -u)
i=0
for word in "${previous_words[@]}" ; do
match=$(printf "$commands" | grep -Fx "$word" 2>/dev/null)
if [[ ! -z "$match" ]] ; then
if [[ ${COMP_WORDS[i-1]} =~ ^(--app-id|--log-level|--server-socket|--term|--title|--window-size-pixels|--window-size-chars|--working-directory)$ ]] ; then
(( i++ ))
continue
fi
# positional argument found
offset=$i
fi
(( i++ ))
done
if [[ ! -z "$offset" ]] ; then
# depends on bash_completion being available
declare -F _command_offset >/dev/null || return 1
_command_offset $offset
elif [[ ${cur} == --* ]] ; then
COMPREPLY=( $(compgen -W "${flags}" -- ${cur}) )
elif [[ ${prev} == '--server-socket' ]] ; then
compopt -o default
elif [[ ${prev} == '--working-directory' ]] ; then
compopt -o dirnames
elif [[ ${prev} == '--term' ]] ; then
# check if toe is available
which toe > /dev/null || return 1
COMPREPLY=( $(compgen -W "$(toe -a | awk '$1 ~ /[+]/ {next}; {print $1}')" -- ${cur}) )
elif [[ ${prev} == '--log-level' ]] ; then
COMPREPLY=( $(compgen -W "none error warning info" -- ${cur}) )
elif [[ ${prev} == '--log-colorize' ]] ; then
COMPREPLY=( $(compgen -W "never always auto" -- ${cur}) )
elif [[ ${prev} =~ ^(--app-id|--help|--override|--title|--version|--window-size-chars|--window-size-pixels|)$ ]] ; then
: # don't autocomplete for these flags
else
# complete commands from $PATH
COMPREPLY=( $(compgen -c ${cur}) )
fi
return 0
}
complete -F _footclient footclient
|