-
Notifications
You must be signed in to change notification settings - Fork 32
/
bash-completion
97 lines (88 loc) · 2.25 KB
/
bash-completion
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
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/sh
#
# Copyright (C) 2017-2024 Savoir-faire Linux, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
if [ -z "$BASH_VERSION" ]; then
_init_completion() {
}
_get_first_arg() {
}
fi
_cqfd() {
local cur prev words cword
_init_completion || return
case $prev in
-C|-d|-f)
_filedir
return
;;
-b)
local flavors cqfdrc=.cqfdrc
# before we scan for flavors, see if a cqfdrc name was
# specified with -f
for (( i=0; i < ${#words[@]}; i++ )); do
if [[ ${words[i]} == -f ]]; then
# eval for tilde expansion
eval cqfdrc=( "${words[i+1]}" )
fi
done
if [ -e "$cqfdrc" ]; then
flavors=$(cqfd -f $cqfdrc flavors)
COMPREPLY=( $(compgen -W "$flavors" -- "$cur") )
fi
return
;;
init|flavors|release|help)
return
;;
esac
local arg=
_get_first_arg
if [[ "$arg" == run ]]; then
for (( i=1; i <= cword; i++ )); do
if [[ ${words[i]} == run ]]; then
if [[ $((i+1)) -eq $cword ]]; then
break
elif [[ ${words[i+1]} == -c ]]; then
((i++))
fi
_command_offset $((i + 1))
return
fi
done
COMPREPLY=( $(compgen -c -W "-c" -- "$cur") )
return
elif [[ "$arg" == shell ]]; then
for (( i=1; i <= cword; i++ )); do
if [[ ${words[i]} == shell ]]; then
((i++))
break
fi
done
COMP_WORDS=("${SHELL:-/bin/sh}" "${COMP_WORDS[@]:$i}" "$cur")
COMP_LINE="${COMP_WORDS[*]}"
COMP_POINT="${#COMP_LINE}"
_command_offset 0
return
fi
local opts="-C -d -f -b -q -V --version -h --help"
if [[ "$cur" == -* ]]; then
COMPREPLY=( $(compgen -W "$opts" -- "$cur") )
return
fi
local cmds="init flavors run release shell version help"
COMPREPLY=( $(compgen -W "$cmds $opts" -- "$cur") )
} &&
complete -F _cqfd cqfd