3 # Helper script for completion, usage with tcsh:
5 # complete osc 'p@*@`osc.complete`@'
9 # complete -C osc.complete osc
11 # Author: Werner Fink <werner@suse.de>
19 test "/proc/$PPID/exe" -ef /bin/tcsh || COMMAND_LINE="$COMP_LINE"
20 cmdline=($COMMAND_LINE)
21 test "${cmdline[0]}" != "osc" && exit 1
23 let last=${#COMMAND_LINE}
25 let count=${#cmdline[@]}
27 test "${COMMAND_LINE:$last}" = " " && let count++
30 osccmds=(abortbuild add addremove ar aggregatepac api branch build buildconfig \
31 buildhistory buildhist buildinfo buildlog bl cat changedevelrequest changedevelreq \
32 cr checkout co commit checkin ci copypac delete del remove rm deleterequest \
33 deletereq dr diff di getbinaries help importsrcpkg info init jobhistory jobhist \
34 linkpac list ls log maintainer man meta mkpac platforms prjresults pr rdelete \
35 rdiff rebuild rebuildpac remotebuildlog rbl rbuildlog repairlink repos repourls \
36 request rq resolved results r search setlinkrev status st submitrequest sr \
37 submitreq update up updatepacmetafromspec metafromspec vc wipebinaries)
38 oscreq=(list log show accept decline delete revoke wipe)
44 test -s ${PWD}/.osc/_project && read -t 1 oscprj < ${PWD}/.osc/_project
45 test -s ${PWD}/.osc/_package && read -t 1 oscpkg < ${PWD}/.osc/_package
46 if test -s ${PWD}/.osc/_files ; then
47 lnkprj=$(command sed -rn '/<linkinfo/{s@.*[[:blank:]]project="([^"]+)".*@\1@p;}' < ${PWD}/.osc/_files)
48 lnkpkg=$(command sed -rn '/<linkinfo/{s@.*[[:blank:]]package="([^"]+)".*@\1@p;}' < ${PWD}/.osc/_files)
51 if test -s ~/.osc.projects ; then
52 typeset -i ctime=$(command date -d "$(command stat -c '%z' ~/.osc.projects)" +'%s')
53 typeset -i now=$(command date -d now +'%s')
54 ((now - ctime > 86400)) && command osc ls >| ~/.osc.projects
56 command osc ls >| ~/.osc.projects
65 if ((pos == 1)) ; then
66 if test -z "${cmdline[$((2+off))]}" -a -n "${oscprj}" ; then
67 builtin compgen -W "${oscprj}"
69 builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[$((2+off))]}"
72 if ((pos == 2)) ; then
73 if test -z "${cmdline[$((3+off))]}" -a -n "${oscpkg}" ; then
74 builtin compgen -W "${oscpkg}"
76 builtin compgen -W "$(command osc ls "${cmdline[$((2+off))]}")" -- "${cmdline[$((3+off))]}"
79 if ((pos == 3)) ; then
80 if test -z "${cmdline[$((4+off))]}" -a -n "${lnkprj}" ; then
81 builtin compgen -W "${lnkprj}"
83 builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[$((4+off))]}"
86 if ((pos == 4)) ; then
88 target="${target:+$target }$oscpkg"
89 if test -n "${target}" ; then
90 builtin compgen -W "${target}" -- "${cmdline[$((5+off))]}"
92 builtin compgen -W "$(command osc ls "${cmdline[$((4+off))]}")" -- "${cmdline[$((5+off))]}"
97 case "${cmdline[1]}" in
99 if ((count == 1)) ; then
100 builtin compgen -W 'add addremove ar' -- "${cmdline[1]}"
102 for x in $(builtin compgen -f -X '.osc' -- "${cmdline[2]}"); do
103 test -d $x && builtin echo $x/ || builtin echo $x
108 if ((count == 1)) ; then
109 builtin compgen -W 'branch' -- "${cmdline[1]}"
111 case "${cmdline[2]}" in
113 if ((count == 3)) ; then
114 builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[3]}"
116 if ((count == 4)) ; then
117 builtin compgen -W "$(command osc ls "${cmdline[3]}")" -- "${cmdline[4]}"
120 -*) builtin compgen -W '--nodevelproject' -- "${cmdline[3]}" ;;
122 if ((count == 2)) ; then
123 builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}"
125 if ((count == 3)) ; then
126 builtin compgen -W "$(command osc ls "${cmdline[2]}")" -- "${cmdline[3]}"
131 if ((count == 1)) ; then
132 builtin compgen -W 'list ls' -- "${cmdline[1]}"
134 if ((count == 2)) ; then
135 builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}"
137 if ((count == 3)) ; then
138 builtin compgen -W "$(command osc ls "${cmdline[2]}")" -- "${cmdline[3]}"
141 sr|submitreq|submitrequest)
142 if ((count == 1)) ; then
143 builtin compgen -W 'sr submitreq submitrequest' -- "${cmdline[1]}"
145 case "${cmdline[2]}" in
147 submit $((count - 2)) 1 ;;
148 -*) builtin compgen -W '--nodevelproject' -- "${cmdline[2]}" ;;
149 *) submit $((count - 1)) 0 ;;
153 if ((count == 1)) ; then
154 builtin compgen -W 'rq request' -- "${cmdline[1]}"
156 case "${cmdline[2]}" in
157 accept|decline|wipe|revoke|log)
158 if ((count == 3)) ; then
163 if ((count == 3)) ; then
164 builtin compgen -W '--diff' -- "${cmdline[3]}"
170 if ((count == 3)) ; then
171 builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[3]}"
173 if ((count == 4)) ; then
174 builtin compgen -W "$(command osc ls "${cmdline[3]}")" -- "${cmdline[4]}"
178 ((count == 2)) && builtin compgen -W "$(builtin echo ${oscreq[@]})" -- "${cmdline[2]}"
182 if ((count == 1)) ; then
183 builtin compgen -W 'copypac linkpac' -- "${cmdline[1]}"
185 case "${cmdline[2]}" in
187 if ((count == 2)) ; then
188 builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}"
190 if ((count == 3)) ; then
191 builtin compgen -W "$(osc ls "${cmdline[2]}")" -- "${cmdline[3]}"
193 if ((count == 4)) ; then
194 builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[4]}"
196 if ((count == 5)) ; then
197 builtin compgen -W "$(command osc ls "${cmdline[4]}")" -- "${cmdline[5]}"
201 deleterequest|deletereq|dr)
202 if ((count == 1)) ; then
203 builtin compgen -W 'deleterequest deletereq dr' -- "${cmdline[1]}"
205 case "${cmdline[2]}" in
207 if ((count == 2)) ; then
208 builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}"
210 if ((count == 3)) ; then
211 builtin compgen -W "$(osc ls "${cmdline[2]}")" -- "${cmdline[3]}"
215 changedevelrequest|changedevelreq|cr)
216 if ((count == 1)) ; then
217 builtin compgen -W 'changedevelrequest changedevelreq cr' -- "${cmdline[1]}"
219 case "${cmdline[2]}" in
221 if ((count == 2)) ; then
222 builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}"
224 if ((count == 3)) ; then
225 builtin compgen -W "$(osc ls "${cmdline[2]}")" -- "${cmdline[3]}"
227 if ((count == 4)) ; then
228 builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[4]}"
230 if ((count == 5)) ; then
231 builtin compgen -W "$(command osc ls "${cmdline[4]}")" -- "${cmdline[5]}"
236 if ((count == 1)) ; then
237 builtin compgen -W 'rdiff' -- "${cmdline[1]}"
239 case "${cmdline[2]}" in
241 if ((count == 2)) ; then
242 builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}"
244 if ((count == 3)) ; then
245 builtin compgen -W "$(osc ls "${cmdline[2]}")" -- "${cmdline[3]}"
247 if ((count == 4)) ; then
248 builtin compgen -W "$(command cat ~/.osc.projects)" -P --oldprj= -- "${cmdline[4]#*=}"
250 if ((count == 5)) ; then
251 builtin compgen -W "$(command osc ls "${cmdline[4]}")" -P --oldpkg= -- "${cmdline[5]#*=}"
256 if ((count == 1)) ; then
257 builtin compgen -W 'ci commit checkin' -- "${cmdline[1]}"
259 for x in $(builtin compgen -f -X '.osc' -- "${cmdline[2]}"); do
260 test -d $x && builtin echo $x/ || builtin echo $x
265 if ((count == 1)) ; then
266 builtin compgen -W 'co copypac checkout' -- "${cmdline[1]}"
268 if ((count == 2)) ; then
269 builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}"
271 if ((count == 3)) ; then
272 builtin compgen -W "$(command osc ls "${cmdline[2]}")" -- "${cmdline[3]}"
277 if ((count == 1)) ; then
278 builtin compgen -W 'maintainer' -- "${cmdline[1]}"
280 if ((count == 2)) ; then
281 builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}"
283 if ((count == 3)) ; then
284 builtin compgen -W "$(command osc ls "${cmdline[2]}")" -- "${cmdline[3]}"
289 if ((count == 1)) ; then
290 builtin compgen -W 'up update' -- "${cmdline[1]}"
292 if ((count == 2)) ; then
293 builtin compgen -W '--expand-link --unexpand-link' -- "${cmdline[2]}"
297 if ((count == 1)) ; then
298 builtin compgen -W 'meta metafromspec' -- "${cmdline[1]}"
300 if ((count == 2)) ; then
301 builtin compgen -W 'prj pkg' -- "${cmdline[2]}"
303 if ((count == 3)) ; then
304 builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[3]}"
306 if ((count == 4)) && test "${cmdline[2]}" = pkg ; then
307 builtin compgen -W "$(command osc ls "${cmdline[3]}")" -- "${cmdline[4]}"
309 if ((count == 5)) ; then
310 builtin compgen -W '--edit -e' -- "${cmdline[5]}"
314 if ((count == 1)) ; then
315 builtin compgen -W 'wipebinaries' -- "${cmdline[1]}"
317 if ((count == 2)) ; then
318 builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}"
320 if ((count == 3)) ; then
321 builtin compgen -W "$(command osc ls "${cmdline[2]}")" -- "${cmdline[3]}"
323 if ((count == 4)) ; then
324 builtin compgen -W "--expansion --broken --build-failed --build-disabled" -- "${cmdline[4]}"
328 if ((count == 1)) ; then
329 builtin compgen -W 'help' -- "${cmdline[1]}"
331 ((count == 2)) && builtin compgen -W "$(builtin echo ${osccmds[@]})" -- "${cmdline[2]}"
334 if ((count == 1)) ; then
335 builtin compgen -W 'search' -- "${cmdline[1]}"
337 oscsearch="--help --csv -i --involved -v --verbose --description --title \
338 --project --package -e --exact --repos-baseurl"
339 builtin compgen -W "${oscsearch}" -- "${cmdline[$count]}"
343 ((count == 1)) && builtin compgen -W "$(builtin echo ${osccmds[@]})" -- "${cmdline[1]}"