1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-12-27 10:16:14 +01:00
github.com_openSUSE_osc/dist/osc.complete

397 lines
13 KiB
Plaintext
Raw Normal View History

#!/bin/bash
#
# Helper script for completion, usage with tcsh:
#
# complete osc 'p@*@`osc.complete`@'
#
# usage with bash
#
# complete -C osc.complete osc
#
# Author: Werner Fink <werner@suse.de>
#
set -o noclobber
shopt -s extglob
typeset -i last
typeset -i count
test "/proc/$PPID/exe" -ef /bin/tcsh || COMMAND_LINE="$COMP_LINE"
cmdline=($COMMAND_LINE)
test "${cmdline[0]}" != "osc" && exit 1
let last=${#COMMAND_LINE}
let last--
let count=${#cmdline[@]}
let count--
test "${COMMAND_LINE:$last}" = " " && let count++
unset last
osccmds=(abortbuild add addremove ar aggregatepac api branch bugowner build buildconfig \
buildhistory buildhist buildinfo buildlog bl cat changedevelrequest changedevelreq \
cr checkout co commit checkin ci chroot config copypac createrequest creq delete del
remove rm deleterequest deletereq dr dependson whatdependson diff di distributions dists \
getbinaries help importsrcpkg info init jobhistory jobhist linkpac linktobranch list ls \
log localbuildlog lbl maintainer man mbranch meta mkpac mv my patchinfo platforms \
prjresults pr pull rdelete rdiff rebuild rebuildpac remotebuildlog rbl rbuildlog \
repairlink repos repositories platforms repourls request rq review rremove resolved \
results r search bse se sm setlinkrev signkey status st submitrequest sr submitpac \
submitreq triggerreason tr undelete update up updatepacmetafromspec metafromspec vc \
wipebinaries)
oscreq=(list log show accept decline delete revoke wipe)
oscmy=(pkg prj rq sr)
oscprj=""
oscpkg=""
lnkprj=""
lnkpkg=""
test -s ${PWD}/.osc/_project && read -t 1 oscprj < ${PWD}/.osc/_project
test -s ${PWD}/.osc/_package && read -t 1 oscpkg < ${PWD}/.osc/_package
if test -s ${PWD}/.osc/_files ; then
lnkprj=$(command sed -rn '/<linkinfo/{s@.*[[:blank:]]project="([^"]+)".*@\1@p;}' < ${PWD}/.osc/_files)
lnkpkg=$(command sed -rn '/<linkinfo/{s@.*[[:blank:]]package="([^"]+)".*@\1@p;}' < ${PWD}/.osc/_files)
fi
if test -s ~/.osc.projects ; then
typeset -i ctime=$(command date -d "$(command stat -c '%z' ~/.osc.projects)" +'%s')
typeset -i now=$(command date -d now +'%s')
((now - ctime > 86400)) && command osc ls >| ~/.osc.projects
else
command osc ls >| ~/.osc.projects
fi
submit ()
{
local -i pos=$1
local -i off=$2
local target
if ((pos == 1)) ; then
2009-10-20 16:30:15 +02:00
if test -z "${cmdline[$((2+off))]}" -a -n "${oscprj}" ; then
builtin compgen -W "${oscprj}"
else
builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[$((2+off))]}"
fi
fi
if ((pos == 2)) ; then
2009-10-20 16:30:15 +02:00
if test -z "${cmdline[$((3+off))]}" -a -n "${oscpkg}" ; then
builtin compgen -W "${oscpkg}"
else
builtin compgen -W "$(command osc ls "${cmdline[$((2+off))]}")" -- "${cmdline[$((3+off))]}"
fi
fi
if ((pos == 3)) ; then
2009-10-20 16:30:15 +02:00
if test -z "${cmdline[$((4+off))]}" -a -n "${lnkprj}" ; then
builtin compgen -W "${lnkprj}"
else
builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[$((4+off))]}"
fi
fi
if ((pos == 4)) ; then
2009-10-20 16:30:15 +02:00
target="${lnkpkg}"
target="${target:+$target }$oscpkg"
if test -n "${target}" ; then
builtin compgen -W "${target}" -- "${cmdline[$((5+off))]}"
else
builtin compgen -W "$(command osc ls "${cmdline[$((4+off))]}")" -- "${cmdline[$((5+off))]}"
fi
fi
}
case "${cmdline[1]}" in
add|addremove|ar)
if ((count == 1)) ; then
2009-10-20 16:30:15 +02:00
builtin compgen -W 'add addremove ar' -- "${cmdline[1]}"
else
2009-10-20 16:30:15 +02:00
for x in $(builtin compgen -f -X '.osc' -- "${cmdline[2]}"); do
test -d $x && builtin echo $x/ || builtin echo $x
done
fi
;;
branch)
if ((count == 1)) ; then
2009-10-20 16:30:15 +02:00
builtin compgen -W 'branch' -- "${cmdline[1]}"
fi
case "${cmdline[2]}" in
--nodevelproject)
2009-10-20 16:30:15 +02:00
if ((count == 3)) ; then
builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[3]}"
fi
if ((count == 4)) ; then
builtin compgen -W "$(command osc ls "${cmdline[3]}")" -- "${cmdline[4]}"
fi
;;
-*) builtin compgen -W '--nodevelproject' -- "${cmdline[3]}" ;;
*)
2009-10-20 16:30:15 +02:00
if ((count == 2)) ; then
builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}"
fi
if ((count == 3)) ; then
builtin compgen -W "$(command osc ls "${cmdline[2]}")" -- "${cmdline[3]}"
fi
esac
;;
list|ls)
if ((count == 1)) ; then
2009-10-20 16:30:15 +02:00
builtin compgen -W 'list ls' -- "${cmdline[1]}"
fi
if ((count == 2)) ; then
2009-10-20 16:30:15 +02:00
builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}"
fi
if ((count == 3)) ; then
2009-10-20 16:30:15 +02:00
builtin compgen -W "$(command osc ls "${cmdline[2]}")" -- "${cmdline[3]}"
fi
;;
sr|submitreq|submitrequest)
if ((count == 1)) ; then
2009-10-20 16:30:15 +02:00
builtin compgen -W 'sr submitreq submitrequest' -- "${cmdline[1]}"
fi
case "${cmdline[2]}" in
--nodevelproject)
2009-10-20 16:30:15 +02:00
submit $((count - 2)) 1 ;;
-*) builtin compgen -W '--nodevelproject' -- "${cmdline[2]}" ;;
*) submit $((count - 1)) 0 ;;
esac
;;
rq|request)
if ((count == 1)) ; then
2009-10-20 16:30:15 +02:00
builtin compgen -W 'rq request' -- "${cmdline[1]}"
fi
case "${cmdline[2]}" in
accept|decline|wipe|revoke|log)
2009-10-20 16:30:15 +02:00
if ((count == 3)) ; then
builtin echo -n 'ID'
fi
;;
show)
2009-10-20 16:30:15 +02:00
if ((count == 3)) ; then
builtin compgen -W '--diff' -- "${cmdline[3]}"
2010-02-28 02:30:13 +01:00
else
2009-10-20 16:30:15 +02:00
builtin echo -n 'ID'
fi
;;
list)
2009-10-20 16:30:15 +02:00
if ((count == 3)) ; then
builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[3]}"
fi
if ((count == 4)) ; then
builtin compgen -W "$(command osc ls "${cmdline[3]}")" -- "${cmdline[4]}"
fi
;;
*)
2009-10-20 16:30:15 +02:00
((count == 2)) && builtin compgen -W "$(builtin echo ${oscreq[@]})" -- "${cmdline[2]}"
esac
;;
my)
if ((count == 1)) ; then
builtin compgen -W 'my' -- "${cmdline[1]}"
fi
if ((count == 2)) ; then
builtin compgen -W "$(builtin echo ${oscmy[@]})" -- "${cmdline[2]}"
fi
;;
copypac|linkpac)
if ((count == 1)) ; then
2009-10-20 16:30:15 +02:00
builtin compgen -W 'copypac linkpac' -- "${cmdline[1]}"
fi
case "${cmdline[2]}" in
*)
2009-10-20 16:30:15 +02:00
if ((count == 2)) ; then
builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}"
fi
if ((count == 3)) ; then
builtin compgen -W "$(osc ls "${cmdline[2]}")" -- "${cmdline[3]}"
fi
if ((count == 4)) ; then
builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[4]}"
fi
if ((count == 5)) ; then
builtin compgen -W "$(command osc ls "${cmdline[4]}")" -- "${cmdline[5]}"
fi
esac
;;
deleterequest|deletereq|dr)
if ((count == 1)) ; then
2009-10-20 16:30:15 +02:00
builtin compgen -W 'deleterequest deletereq dr' -- "${cmdline[1]}"
fi
case "${cmdline[2]}" in
*)
2009-10-20 16:30:15 +02:00
if ((count == 2)) ; then
builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}"
fi
if ((count == 3)) ; then
builtin compgen -W "$(osc ls "${cmdline[2]}")" -- "${cmdline[3]}"
fi
esac
;;
changedevelrequest|changedevelreq|cr)
if ((count == 1)) ; then
2009-10-20 16:30:15 +02:00
builtin compgen -W 'changedevelrequest changedevelreq cr' -- "${cmdline[1]}"
fi
case "${cmdline[2]}" in
*)
2009-10-20 16:30:15 +02:00
if ((count == 2)) ; then
builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}"
fi
if ((count == 3)) ; then
builtin compgen -W "$(osc ls "${cmdline[2]}")" -- "${cmdline[3]}"
fi
if ((count == 4)) ; then
builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[4]}"
fi
if ((count == 5)) ; then
builtin compgen -W "$(command osc ls "${cmdline[4]}")" -- "${cmdline[5]}"
fi
esac
;;
rdiff)
if ((count == 1)) ; then
2009-10-20 16:30:15 +02:00
builtin compgen -W 'rdiff' -- "${cmdline[1]}"
fi
case "${cmdline[2]}" in
*)
2009-10-20 16:30:15 +02:00
if ((count == 2)) ; then
builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}"
fi
if ((count == 3)) ; then
builtin compgen -W "$(osc ls "${cmdline[2]}")" -- "${cmdline[3]}"
fi
if ((count == 4)) ; then
builtin compgen -W "$(command cat ~/.osc.projects)" -P --oldprj= -- "${cmdline[4]#*=}"
fi
if ((count == 5)) ; then
builtin compgen -W "$(command osc ls "${cmdline[4]#*=}")" -P --oldpkg= -- "${cmdline[5]#*=}"
fi
esac
;;
ci|commit|checkin)
if ((count == 1)) ; then
2009-10-20 16:30:15 +02:00
builtin compgen -W 'ci commit checkin' -- "${cmdline[1]}"
else
2009-10-20 16:30:15 +02:00
for x in $(builtin compgen -f -X '.osc' -- "${cmdline[2]}"); do
test -d $x && builtin echo $x/ || builtin echo $x
done
fi
;;
co|checkout)
if ((count == 1)) ; then
2009-10-20 16:30:15 +02:00
builtin compgen -W 'co copypac checkout' -- "${cmdline[1]}"
else
2009-10-20 16:30:15 +02:00
if ((count == 2)) ; then
builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}"
fi
if ((count == 3)) ; then
builtin compgen -W "$(command osc ls "${cmdline[2]}")" -- "${cmdline[3]}"
fi
fi
;;
2009-07-01 17:34:05 +02:00
maintainer)
if ((count == 1)) ; then
2009-10-20 16:30:15 +02:00
builtin compgen -W 'maintainer' -- "${cmdline[1]}"
2009-07-01 17:34:05 +02:00
else
2009-10-20 16:30:15 +02:00
if ((count == 2)) ; then
builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}"
fi
if ((count == 3)) ; then
builtin compgen -W "$(command osc ls "${cmdline[2]}")" -- "${cmdline[3]}"
fi
2009-07-01 17:34:05 +02:00
fi
;;
up|update)
if ((count == 1)) ; then
2009-10-20 16:30:15 +02:00
builtin compgen -W 'up update' -- "${cmdline[1]}"
fi
if ((count == 2)) ; then
2009-10-20 16:30:15 +02:00
builtin compgen -W '--expand-link --unexpand-link' -- "${cmdline[2]}"
fi
;;
meta)
if ((count == 1)) ; then
2009-10-20 16:30:15 +02:00
builtin compgen -W 'meta metafromspec' -- "${cmdline[1]}"
fi
if ((count == 2)) ; then
2009-10-20 16:30:15 +02:00
builtin compgen -W 'prj pkg' -- "${cmdline[2]}"
fi
if ((count == 3)) ; then
2009-10-20 16:30:15 +02:00
builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[3]}"
fi
if ((count == 4)) && test "${cmdline[2]}" = pkg ; then
2009-10-20 16:30:15 +02:00
builtin compgen -W "$(command osc ls "${cmdline[3]}")" -- "${cmdline[4]}"
fi
if ((count == 5)) ; then
2009-10-20 16:30:15 +02:00
builtin compgen -W '--edit -e' -- "${cmdline[5]}"
fi
;;
wipebinaries)
if ((count == 1)) ; then
2009-10-20 16:30:15 +02:00
builtin compgen -W 'wipebinaries' -- "${cmdline[1]}"
fi
if ((count == 2)) ; then
2009-10-20 16:30:15 +02:00
builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}"
fi
if ((count == 3)) ; then
2009-10-20 16:30:15 +02:00
builtin compgen -W "$(command osc ls "${cmdline[2]}")" -- "${cmdline[3]}"
fi
if ((count == 4)) ; then
2009-10-20 16:30:15 +02:00
builtin compgen -W "--expansion --broken --build-failed --build-disabled" -- "${cmdline[4]}"
fi
;;
help)
if ((count == 1)) ; then
2009-10-20 16:30:15 +02:00
builtin compgen -W 'help' -- "${cmdline[1]}"
fi
((count == 2)) && builtin compgen -W "$(builtin echo ${osccmds[@]})" -- "${cmdline[2]}"
;;
2009-07-01 17:51:34 +02:00
search)
if ((count == 1)) ; then
2009-10-20 16:30:15 +02:00
builtin compgen -W 'search' -- "${cmdline[1]}"
2009-07-01 17:51:34 +02:00
else
2009-10-20 16:30:15 +02:00
oscsearch="--help --csv -i --involved -v --verbose --description --title \
--project --package -e --exact --repos-baseurl"
builtin compgen -W "${oscsearch}" -- "${cmdline[$count]}"
2009-07-01 17:51:34 +02:00
fi
;;
pr|prjresults)
if ((count == 1)) ; then
2009-10-20 16:30:15 +02:00
builtin compgen -W 'pr prjresults' -- "${cmdline[1]}"
fi
if ((count == 2)) ; then
2009-10-20 16:30:15 +02:00
builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}"
fi
if ((count > 2)) ; then
2009-10-20 16:30:15 +02:00
case "${cmdline[$((count-1))]}" in
-n|--name-filter*)
builtin compgen -W "$(command osc ls "${cmdline[2]}")" -- "${cmdline[$count]}"
;;
-s|--status-filter*)
OIFS="$IFS"; IFS=:
builtin compgen -W 'disabled:failed:finished:building:succeeded:broken:scheduled:unresolvable:signing:blocked' -- "${cmdline[$count]}"
2009-10-20 16:30:15 +02:00
IFS="$OIFS"
;;
-p|--project*)
builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[$count]}"
;;
*)
builtin compgen -W "-n --name-filter -s --status-filter -c --csv -q --hide-legend" -- "${cmdline[$count]}"
;;
esac
fi
;;
r|results)
if ((count == 1)) ; then
2009-10-20 16:30:15 +02:00
builtin compgen -W 'r results' -- "${cmdline[1]}"
fi
if ((count == 2)) ; then
2009-10-20 16:30:15 +02:00
builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}"
fi
if ((count == 3)) ; then
2009-10-20 16:30:15 +02:00
builtin compgen -W "$(command osc ls "${cmdline[2]}")" -- "${cmdline[3]}"
fi
if ((count > 3)) ; then
2009-10-20 16:30:15 +02:00
builtin compgen -W "-r --repo -a --arch -l --last-build --xml" -- "${cmdline[$count]}"
fi
;;
*)
((count == 1)) && builtin compgen -W "$(builtin echo ${osccmds[@]})" -- "${cmdline[1]}"
esac