diff options
Diffstat (limited to 'contrib/cvs')
-rw-r--r-- | contrib/cvs | 316 |
1 files changed, 221 insertions, 95 deletions
diff --git a/contrib/cvs b/contrib/cvs index aa2d46c9..04837cd1 100644 --- a/contrib/cvs +++ b/contrib/cvs @@ -23,83 +23,116 @@ get_modules() fi } +_cvs_commands() +{ + cvs --help-commands 2>&1 | awk '/^( *|\t)/ { print $1 }' +} + +_cvs_options() +{ + cvs --help-options 2>&1 | awk '/^( *|\t)-/ { print $1 }' +} + +_cvs_command_options() +{ + cvs --help $1 2>&1 | sed -ne 's/^[[:space:]]*\(-[^[:space:]=[]*\).*/\1/p' +} + +_cvs_kflags() +{ + COMPREPLY=( $( compgen -W 'kv kvl k o b v' -- "$cur" ) ) +} + +_cvs_roots() +{ + local -a cvsroots + cvsroots=( $CVSROOT ) + [ -r ~/.cvspass ] && \ + cvsroots=( "${cvsroots[@]}" $( awk '{ print $2 }' ~/.cvspass ) ) + [ -r CVS/Root ] && cvsroots=( "${cvsroots[@]}" $(cat CVS/Root) ) + COMPREPLY=( $( compgen -W '${cvsroots[@]}' -- "$cur" ) ) + __ltrim_colon_completions "$cur" +} + _cvs() { - local cur count mode i cvsroot cvsroots pwd + local cur prev count mode i cvsroot cvsroots pwd local -a flags miss files entries changed newremoved COMPREPLY=() - cur=`_get_cword` + _get_comp_words_by_ref -n : cur prev count=0 for i in "${COMP_WORDS[@]}"; do [ $count -eq $COMP_CWORD ] && break # Last parameter was the CVSROOT, now go back to mode selection - if [ "${COMP_WORDS[((count))]}" == "$cvsroot" -a "$mode" == "cvsroot" ]; then + if [[ "${COMP_WORDS[((count))]}" == "$cvsroot" && "$mode" == cvsroot ]]; then mode="" fi if [ -z "$mode" ]; then case $i in - -d) - mode=cvsroot - cvsroot=${COMP_WORDS[((count+1))]} - ;; - @(ad?(d)|new)) - mode=add - ;; - @(adm?(in)|rcs)) - mode=admin - ;; - ann?(notate)) - mode=annotate - ;; - @(checkout|co|get)) - mode=checkout - ;; - @(com?(mit)|ci)) - mode=commit - ;; - di?(f?(f))) - mode=diff - ;; - ex?(p?(ort))) - mode=export - ;; - ?(un)edit) - mode=$i - ;; - hi?(s?(tory))) - mode=history - ;; - im?(p?(ort))) - mode=import - ;; - re?(l?(ease))) - mode=release - ;; - ?(r)log) - mode=log - ;; - @(rdiff|patch)) - mode=rdiff - ;; - @(remove|rm|delete)) - mode=remove - ;; - @(rtag|rfreeze)) - mode=rtag - ;; - st?(at?(us))) - mode=status - ;; - @(tag|freeze)) - mode=tag - ;; - up?(d?(ate))) - mode=update - ;; - *) - ;; + -H|--help) + COMPREPLY=( $( compgen -W "$( _cvs_commands )" -- "$cur" ) ) + return 0 + ;; + -d) + mode=cvsroot + cvsroot=${COMP_WORDS[((count+1))]} + ;; + ad|add|new) + mode=add + ;; + adm|admin|rcs) + mode=admin + ;; + ann|annotate) + mode=annotate + ;; + checkout|co|get) + mode=checkout + ;; + com|commit|ci) + mode=commit + ;; + di|dif|diff) + mode=diff + ;; + ex|exp|export) + mode=export + ;; + edit|unedit) + mode=$i + ;; + hi|his|history) + mode=history + ;; + im|imp|import) + mode=import + ;; + re|rel|release) + mode=release + ;; + log|rlog) + mode=log + ;; + rdiff|patch) + mode=rdiff + ;; + remove|rm|delete) + mode=remove + ;; + rtag|rfreeze) + mode=rtag + ;; + st|stat|status) + mode=status + ;; + tag|freeze) + mode=tag + ;; + up|upd|update) + mode=update + ;; esac elif [[ "$i" = -* ]]; then flags=( "${flags[@]}" $i ) @@ -107,11 +140,21 @@ _cvs() count=$((++count)) done - case "$mode" in + case $mode in add) + case $prev in + -m) + return 0 + ;; + -k) + _cvs_kflags + return 0 + ;; + esac + if [[ "$cur" != -* ]]; then set_prefix - if [ $COMP_CWORD -gt 1 -a -r ${prefix:-}CVS/Entries ]; then + if [[ $COMP_CWORD -gt 1 && -r ${prefix:-}CVS/Entries ]]; then get_entries [ -z "$cur" ] && \ files=$( command ls -Ad !(CVS) ) || \ @@ -122,35 +165,77 @@ _cvs() COMPREPLY=( $( compgen -X '*~' -W '${files[@]}' -- $cur ) ) fi else - COMPREPLY=( $( compgen -W '-k -m' -- "$cur" ) ) + COMPREPLY=( $( compgen -W "$( _cvs_command_options $mode )" \ + -- "$cur" ) ) fi ;; admin) + case $prev in + -a|-A|-b|-c|-e|-l|-m|-n|-N|-o|-s|-t-|-u) + return 0 + ;; + -t) + _filedir + return 0 + ;; + -k) + _cvs_kflags + return 0 + ;; + esac + if [[ "$cur" = -* ]]; then - COMPREPLY=( $( compgen -W '-i -a -A -e -b -c -k -l -u -L -U -m -M \ - -n -N -o -q -I -s -t -t- -T -V -x -z' -- $cur ) ) + COMPREPLY=( $( compgen -W "$( _cvs_command_options $mode )" \ + -- "$cur" ) ) fi ;; annotate) + [[ "$prev" == -@(r|D) ]] && return 0 + if [[ "$cur" = -* ]]; then - COMPREPLY=( $( compgen -W '-D -F -f -l -R -r' -- "$cur" ) ) + COMPREPLY=( $( compgen -W "$( _cvs_command_options $mode )" \ + -- "$cur" ) ) else get_entries COMPREPLY=( $( compgen -W '${entries[@]}' -- "$cur" ) ) fi ;; checkout) + case $prev in + -r|-D|j) + return 0 + ;; + -d) + _filedir -d + return 0 + ;; + -k) + _cvs_kflags + return 0 + ;; + esac + if [[ "$cur" != -* ]]; then [ -z "$cvsroot" ] && cvsroot=$CVSROOT COMPREPLY=( $( cvs -d "$cvsroot" co -c 2> /dev/null | \ awk '{print $1}' ) ) COMPREPLY=( $( compgen -W '${COMPREPLY[@]}' -- "$cur" ) ) else - COMPREPLY=( $( compgen -W '-A -N -P -R -c -f -l -n -p \ - -s -r -D -d -k -j' -- "$cur" ) ) + COMPREPLY=( $( compgen -W "$( _cvs_command_options $mode )" \ + -- "$cur" ) ) fi ;; commit) + case $prev in + -m|-r) + return 0 + ;; + -F) + _filedir + return 0 + ;; + esac + set_prefix if [[ "$cur" != -* ]] && [ -r ${prefix:-}CVS/Entries ]; then @@ -169,26 +254,39 @@ _cvs() COMPREPLY=( $( compgen -W '${changed[@]:-} \ ${newremoved[@]:-}' -- "$cur" ) ) else - COMPREPLY=( $(compgen $default -- "$cur") ) + COMPREPLY=( $(compgen -o default -- "$cur") ) fi else - COMPREPLY=( $( compgen -W '-n -R -l -f -F -m -r' -- $cur ) ) + COMPREPLY=( $( compgen -W "$( _cvs_command_options $mode )" \ + -- "$cur" ) ) fi ;; cvsroot) - if [ -r ~/.cvspass ]; then - # Ugly escaping because of bash treating ':' specially - cvsroots=$( sed 's/^[^ ]* //; s/:/\\:/g' ~/.cvspass ) - COMPREPLY=( $( compgen -W '$cvsroots' -- "$cur" ) ) - fi + # TODO: works poorly because of the colons and -o default, + # could we drop -o default? works ok without it in cvsps + _cvs_roots ;; export) + case $prev in + -r|-D) + return 0 + ;; + -d) + _filedir -d + return 0 + ;; + -k) + _cvs_kflags + return 0 + ;; + esac + if [[ "$cur" != -* ]]; then [ -z "$cvsroot" ] && cvsroot=$CVSROOT COMPREPLY=( $( cvs -d "$cvsroot" co -c | awk '{print $1}' ) ) COMPREPLY=( $( compgen -W '${COMPREPLY[@]}' -- "$cur" ) ) else - COMPREPLY=( $( compgen -W '-N -f -l -R -n -r -D -d -k' \ + COMPREPLY=( $( compgen -W "$( _cvs_command_options $mode )" \ -- "$cur" ) ) fi ;; @@ -203,7 +301,7 @@ _cvs() remove) if [[ "$cur" != -* ]]; then set_prefix - if [ $COMP_CWORD -gt 1 -a -r ${prefix:-}CVS/Entries ]; then + if [[ $COMP_CWORD -gt 1 && -r ${prefix:-}CVS/Entries ]]; then get_entries # find out what files are missing for i in "${entries[@]}"; do @@ -212,10 +310,21 @@ _cvs() COMPREPLY=( $(compgen -W '${miss[@]:-}' -- "$cur") ) fi else - COMPREPLY=( $( compgen -W '-f -l -R' -- "$cur" ) ) + COMPREPLY=( $( compgen -W "$( _cvs_command_options $mode )" \ + -- "$cur" ) ) fi ;; import) + case $prev in + -I|-b|-m|-W) + return 0 + ;; + -k) + _cvs_kflags + return 0 + ;; + esac + if [[ "$cur" != -* ]]; then # starts with same algorithm as checkout [ -z "$cvsroot" ] && cvsroot=$CVSROOT @@ -229,32 +338,49 @@ _cvs() pwd=${pwd##*/} COMPREPLY=( $( compgen -W '${COMPREPLY[@]} $pwd' -- $cur ) ) else - COMPREPLY=( $( compgen -W '-d -k -I -b -m -W' -- "$cur" )) + COMPREPLY=( $( compgen -W "$( _cvs_command_options $mode )" \ + -- "$cur" ) ) fi ;; update) + case $prev in + -r|-D|-j|-I|-W) + return 0 + ;; + -k) + _cvs_kflags + return 0 + ;; + esac + if [[ "$cur" = -* ]]; then - COMPREPLY=( $( compgen -W '-A -P -C -d -f -l -R -p \ - -k -r -D -j -I -W' -- "$cur" ) ) + COMPREPLY=( $( compgen -W "$( _cvs_command_options $mode )" \ + -- "$cur" ) ) fi ;; "") - COMPREPLY=( $( compgen -W 'add admin annotate checkout ci co \ - commit diff delete edit export \ - freeze get history import log new \ - patch rcs rdiff release remove \ - rfreeze rlog rm rtag stat status \ - tag unedit up update -H -Q -q -b \ - -d -e -f -l -n -t -r -v -w -x -z \ - --help --version' -- "$cur" ) ) - ;; - *) + case $prev in + -T) + _filedir -d + return 0 + ;; + -e|-s) + return 0 + ;; + -z) + COMPREPLY=( $( compgen -W '1 2 3 4 5 6 7 8 9' -- "$cur" ) ) + return 0 + ;; + esac + + COMPREPLY=( $( compgen -W '$( _cvs_commands ) $( _cvs_options ) \ + --help --help-commands --help-options --version' -- "$cur" ) ) ;; esac return 0 } -complete -F _cvs $default cvs +complete -F _cvs -o default cvs } # Local variables: |