blob: 8ea8a66c1b4ab4374116a121c1e0f36a86b16903 (
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
|
# fedpkg bash completion
have fedpkg &&
_fedpkg()
{
COMPREPLY=()
in_array()
{
local i
for i in $2; do
[[ $i = $1 ]] && return 0
done
return 1
}
local cur prev
# _get_comp_words_by_ref is in bash-completion >= 1.2, which EL-5 lacks.
if type _get_comp_words_by_ref &>/dev/null; then
_get_comp_words_by_ref cur prev
else
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
fi
local paths_exclude="@(.git|*/.git)"
# global options
local options="-h --help -v -q"
local options_value="-u --user --path"
local commands="build chain-build ci clean clog clone co commit compile diff gimmespec giturl help \
import install lint local mockbuild new new-sources patch prep push scratch-build sources srpm \
switch-branch tag-request unused-patches update upload verrel"
# parse main options and get command
local command=
local command_first=
local path=
local i w
for (( i = 0; i < ${#COMP_WORDS[*]} - 1; i++ )); do
w="${COMP_WORDS[$i]}"
# option
if [[ ${w:0:1} = - ]]; then
if in_array "$w" "$options_value"; then
((i++))
[[ "$w" = --path ]] && path="${COMP_WORDS[$i]}"
fi
# command
elif in_array "$w" "$commands"; then
command="$w"
command_first=$((i+1))
break
fi
done
# complete base options
if [[ -z $command ]]; then
case "$prev" in
--user|-u)
;;
--path)
COMPREPLY=( $(compgen -d -X "$paths_exclude" -- "$cur") )
;;
*)
COMPREPLY=( $(compgen -W "$options $options_value $commands" -- "$cur") )
;;
esac
return 0
fi
# parse command specific options
local options=
local options_target= options_arches= options_branch= options_string= options_file= options_srpm=
local after= after_more=
case $command in
help|clog|gimmespec|giturl|lint|mockbuild|new|push|tag-request|unused-patches|update|verrel)
;;
build)
options="--nowait --background --skip-tag --scratch"
options_target="--target"
;;
chain-build)
options="--nowait --background"
options_target="--target"
after="package"
after_more=true
;;
clean)
options="--dry-run -n -x"
;;
clone|co)
options="--branches -B --anonymous -a"
options_branch="-b"
after="package"
;;
commit|ci)
options="--push -p"
options_string="--message -m"
options_file="--file -F"
after="file"
after_more=true
;;
compile|install)
options="--short-circuit"
options_arch="--arch"
;;
diff)
options="--cached"
after="file"
after_more=true
;;
import)
options="--create -c"
options_branch="--branch -b"
after="srpm"
;;
local)
options="--md5"
options_arch="--arch"
;;
patch)
options="--rediff"
options_string="--suffix"
;;
prep)
options_arch="--arch"
;;
scratch-build)
options="--nowait --background --srpm"
options_target="--target"
options_arches="--arches"
options_srpm="--srpm"
;;
sources)
options_dir="--outdir"
;;
srpm)
options="--md5"
;;
switch-branch)
options="--list -l"
after="branch"
;;
upload|new-sources)
after="files"
after_more=true
;;
esac
local all_options="-h --help $options"
local all_options_value="$options_target $options_arches $options_branch $options_string $options_file $options_dir"
# count non-option parametrs
local i w
local last_option=
local after_counter=0
for (( i = $command_first; i < ${#COMP_WORDS[*]} - 1; i++)); do
w="${COMP_WORDS[$i]}"
if [[ ${w:0:1} = - ]]; then
if in_array "$w" "$all_options"; then
last_option="$w"
continue
elif in_array "$w" "$all_options_value"; then
last_option="$w"
((i++))
continue
fi
fi
in_array "$last_option" "$options_arches" || ((after_counter++))
done
# completion
if [[ -n $options_target ]] && in_array "$prev" "$options_target"; then
COMPREPLY=( $(compgen -W "$(_fedpkg_target)" -- "$cur") )
elif [[ -n $options_arches ]] && in_array "$last_option" "$options_arches"; then
COMPREPLY=( $(compgen -W "$(_fedpkg_arch) $all_options" -- "$cur") )
elif [[ -n $options_srpm ]] && in_array "$prev" "$options_srpm"; then
COMPREPLY=( $(compgen -f -o plusdirs -X "!*.src.rpm" -- "$cur") )
elif [[ -n $options_branch ]] && in_array "$prev" "$options_branch"; then
COMPREPLY=( $(compgen -W "$(_fedpkg_branch "$path")" -- "$cur") )
elif [[ -n $options_file ]] && in_array "$prev" "$options_file"; then
COMPREPLY=( $(compgen -f -o plusdirs -X "$paths_exclude" -- "$cur") )
elif [[ -n $options_dir ]] && in_array "$prev" "$options_dir"; then
COMPREPLY=( $(compgen -d -X "$paths_exclude" -- "$cur") )
elif [[ -n $options_string ]] && in_array "$prev" "$options_string"; then
COMPREPLY=( )
else
local compgen_extra=
local after_options=
if [[ $after_counter -eq 0 ]] || [[ $after_more = true ]]; then
case $after in
file) compgen_extra="-o plusdirs -f -X $paths_exclude" ;;
srpm) compgen_extra='-o plusdirs -f -X !*.src.rpm' ;;
branch) after_options="$(_fedpkg_branch "$path")" ;;
package) after_options="$(_fedpkg_package "$cur")";;
esac
fi
COMPREPLY=( $(compgen -W "$all_options $all_options_value $after_options" $compgen_extra -- "$cur" ) )
fi
return 0
} &&
complete -F _fedpkg -o filenames fedpkg
have _fedpkg &&
_fedpkg_target()
{
koji list-targets --quiet 2>/dev/null | cut -d" " -f1
}
have _fedpkg &&
_fedpkg_arch()
{
echo "i386 x86_64 ppc ppc64 s390 s390x sparc sparc64"
}
have _fedpkg &&
_fedpkg_branch()
{
local git_options=
[[ -n $1 ]] && git_options="--git-dir=$1/.git"
git $git_options branch -l 2>/dev/null | sed 's/^\W*//'
git $git_options branch -rl 2>/dev/null | grep -v origin/HEAD | sed 's/^\W*//' | cut -d/ -f2
}
have _fedpkg &&
_fedpkg_package()
{
repoquery -C --qf=%{sourcerpm} "$1*" 2>/dev/null | sort -u | sed -r 's/(-[^-]*){2}\.src\.rpm$//'
}
# Local variables:
# mode: shell-script
# sh-basic-offset: 4
# sh-indent-comment: t
# indent-tabs-mode: nil
# End:
# ex: ts=4 sw=4 et filetype=sh
|