diff options
author | David Paleino <dapal@debian.org> | 2011-11-03 12:32:52 +0100 |
---|---|---|
committer | David Paleino <dapal@debian.org> | 2011-11-03 12:32:52 +0100 |
commit | 2c8171c38d87ddef31c92a76547d3fdf773a1337 (patch) | |
tree | 5e720d5a06ead72ed55454bf6647a712a761ed91 /completions/cvs | |
parent | 9920a8faedf704420571d8072ccab27e9dac40ba (diff) | |
download | bash-completion-2c8171c38d87ddef31c92a76547d3fdf773a1337.tar.gz |
Imported Upstream version 1.90upstream/1.90
Diffstat (limited to 'completions/cvs')
-rw-r--r-- | completions/cvs | 256 |
1 files changed, 127 insertions, 129 deletions
diff --git a/completions/cvs b/completions/cvs index be3b1be7..bafe1901 100644 --- a/completions/cvs +++ b/completions/cvs @@ -1,20 +1,17 @@ -# cvs(1) completion +# cvs(1) completion -*- shell-script -*- -have cvs && { -set_prefix() +_cvs_entries() { - [ -z ${prefix:-} ] || prefix=${cur%/*}/ - [ -r ${prefix:-}CVS/Entries ] || prefix="" -} - -get_entries() -{ - local IFS=$'\n' - [ -r ${prefix:-}CVS/Entries ] && \ - entries=$(cut -d/ -f2 -s ${prefix:-}CVS/Entries) + local prefix=${cur%/*}/ IFS=$'\n' + [[ -e ${prefix:-}CVS/Entries ]] || prefix="" + entries=( $( cut -d/ -f2 -s ${prefix:-}CVS/Entries 2>/dev/null ) ) + if [[ $entries ]]; then + entries=( "${entries[@]/#/${prefix:-}}" ) + compopt -o filenames + fi } -get_modules() +_cvs_modules() { if [ -n "$prefix" ]; then COMPREPLY=( $( command ls -d ${cvsroot}/${prefix}/!(CVSROOT) ) ) @@ -28,14 +25,9 @@ _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' + COMPREPLY=( $( compgen -W '$( _parse_help "$1" "--help $2" )' -- "$cur" ) ) } _cvs_kflags() @@ -48,25 +40,25 @@ _cvs_roots() local -a cvsroots cvsroots=( $CVSROOT ) [ -r ~/.cvspass ] && \ - cvsroots=( "${cvsroots[@]}" $( awk '{ print $2 }' ~/.cvspass ) ) - [ -r CVS/Root ] && cvsroots=( "${cvsroots[@]}" $(cat CVS/Root) ) + cvsroots+=( $( awk '{ print $2 }' ~/.cvspass ) ) + [ -r CVS/Root ] && mapfile -tO ${#cvsroots[@]} cvsroots < CVS/Root COMPREPLY=( $( compgen -W '${cvsroots[@]}' -- "$cur" ) ) __ltrim_colon_completions "$cur" } _cvs() { - local cur prev count mode i cvsroot cvsroots pwd - local -a flags miss files entries changed newremoved + local cur prev words cword + _init_completion -n : || return - COMPREPLY=() - _get_comp_words_by_ref -n : cur prev + local count mode i cvsroot cvsroots pwd + local -a flags miss files entries changed newremoved count=0 - for i in "${COMP_WORDS[@]}"; do - [ $count -eq $COMP_CWORD ] && break + for i in "${words[@]}"; do + [ $count -eq $cword ] && break # Last parameter was the CVSROOT, now go back to mode selection - if [[ "${COMP_WORDS[((count))]}" == "$cvsroot" && "$mode" == cvsroot ]]; then + if [[ "${words[((count))]}" == "$cvsroot" && "$mode" == cvsroot ]]; then mode="" fi if [ -z "$mode" ]; then @@ -77,65 +69,71 @@ _cvs() ;; -d) mode=cvsroot - cvsroot=${COMP_WORDS[((count+1))]} + cvsroot=${words[((count+1))]} ;; - ad|add|new) + add|ad|new) mode=add ;; - adm|admin|rcs) + admin|adm|rcs) mode=admin ;; - ann|annotate) + annotate|ann|blame|rannotate|rann|ra) mode=annotate ;; checkout|co|get) mode=checkout ;; - com|commit|ci) + commit|ci|com) mode=commit ;; - di|dif|diff) + diff|di|dif) mode=diff ;; - ex|exp|export) + export|ex|exp) mode=export ;; - edit|unedit) + edit|unedit|editors|logout|pserver|server|watch|watchers) mode=$i ;; - hi|his|history) + history|hi|his) mode=history ;; - im|imp|import) + import|im|imp) mode=import ;; - re|rel|release) - mode=release - ;; - log|rlog) + log|lo|rlog|rl) mode=log ;; - rdiff|patch) + login|logon|lgn) + mode=login + ;; + rdiff|patch|pa) mode=rdiff ;; + release|re|rel) + mode=release + ;; remove|rm|delete) mode=remove ;; - rtag|rfreeze) + rtag|rt|rfreeze) mode=rtag ;; - st|stat|status) + status|st|stat) mode=status ;; - tag|freeze) + tag|ta|freeze) mode=tag ;; - up|upd|update) + update|up|upd) mode=update ;; + version|ve|ver) + mode=version + ;; esac elif [[ "$i" = -* ]]; then - flags=( "${flags[@]}" $i ) + flags+=( $i ) fi count=$((++count)) done @@ -153,20 +151,26 @@ _cvs() esac if [[ "$cur" != -* ]]; then - set_prefix - if [[ $COMP_CWORD -gt 1 && -r ${prefix:-}CVS/Entries ]]; then - get_entries - [ -z "$cur" ] && \ - files=$( command ls -Ad !(CVS) ) || \ - files=$( command ls -d ${cur}* 2>/dev/null ) - for i in "${entries[@]}"; do - files=( ${files[@]/#$i//} ) - done - COMPREPLY=( $( compgen -X '*~' -W '${files[@]}' -- $cur ) ) - fi - else - COMPREPLY=( $( compgen -W "$( _cvs_command_options $mode )" \ + _cvs_entries + [ -z "$cur" ] && files=( !(CVS) ) || \ + files=( $( command ls -d ${cur}* 2>/dev/null ) ) + local f + for i in ${!files[@]}; do + if [[ ${files[i]} == ?(*/)CVS ]]; then + unset files[i] + else + for f in "${entries[@]}"; do + if [[ ${files[i]} == $f && ! -d $f ]]; then + unset files[i] + break + fi + done + fi + done + COMPREPLY=( $( compgen -X "$_backup_glob" -W '${files[@]}' \ -- "$cur" ) ) + else + _cvs_command_options "$1" $mode fi ;; admin) @@ -185,18 +189,19 @@ _cvs() esac if [[ "$cur" = -* ]]; then - COMPREPLY=( $( compgen -W "$( _cvs_command_options $mode )" \ - -- "$cur" ) ) + _cvs_command_options "$1" $mode + else + _cvs_entries + COMPREPLY=( $( compgen -W '${entries[@]}' -- "$cur" ) ) fi ;; annotate) [[ "$prev" == -@(r|D) ]] && return 0 if [[ "$cur" = -* ]]; then - COMPREPLY=( $( compgen -W "$( _cvs_command_options $mode )" \ - -- "$cur" ) ) + _cvs_command_options "$1" $mode else - get_entries + _cvs_entries COMPREPLY=( $( compgen -W '${entries[@]}' -- "$cur" ) ) fi ;; @@ -221,8 +226,7 @@ _cvs() awk '{print $1}' ) ) COMPREPLY=( $( compgen -W '${COMPREPLY[@]}' -- "$cur" ) ) else - COMPREPLY=( $( compgen -W "$( _cvs_command_options $mode )" \ - -- "$cur" ) ) + _cvs_command_options "$1" $mode fi ;; commit) @@ -236,36 +240,48 @@ _cvs() ;; esac - set_prefix - - if [[ "$cur" != -* && -r ${prefix:-}CVS/Entries ]]; then + if [[ "$cur" != -* ]]; then # if $COMP_CVS_REMOTE is not null, 'cvs commit' will # complete on remotely checked-out files (requires # passwordless access to the remote repository if [ -n "${COMP_CVS_REMOTE:-}" ]; then - # this is the least computationally intensive - # way found so far, but other changes - # (something other than changed/removed/new) - # may be missing - changed=( $( cvs -q diff --brief 2>&1 | \ - sed -ne 's/^Files [^ ]* and \([^ ]*\) differ$/\1/p' ) ) - newremoved=( $( cvs -q diff --brief 2>&1 | \ - sed -ne 's/^cvs diff: \([^ ]*\) .*, no comparison available$/\1/p' ) ) - COMPREPLY=( $( compgen -W '${changed[@]:-} \ - ${newremoved[@]:-}' -- "$cur" ) ) + # this is the least computationally intensive way found so + # far, but other changes (something other than + # changed/removed/new) may be missing + changed=( $( cvs -q diff --brief 2>&1 | \ + sed -ne 's/^Files [^ ]* and \([^ ]*\) differ$/\1/p' ) ) + newremoved=( $( cvs -q diff --brief 2>&1 | \ + sed -ne 's/^cvs diff: \([^ ]*\) .*, no comparison available$/\1/p' ) ) + COMPREPLY=( $( compgen -W '${changed[@]:-} \ + ${newremoved[@]:-}' -- "$cur" ) ) else - COMPREPLY=( $(compgen -o default -- "$cur") ) + _cvs_entries + COMPREPLY=( $( compgen -W '${entries[@]}' -- "$cur" ) ) fi else - COMPREPLY=( $( compgen -W "$( _cvs_command_options $mode )" \ - -- "$cur" ) ) + _cvs_command_options "$1" $mode fi ;; cvsroot) - # TODO: works poorly because of the colons and -o default, - # could we drop -o default? works ok without it in cvsps _cvs_roots ;; + diff) + if [[ "$cur" == -* ]]; then + _cvs_command_options "$1" $mode + [[ $COMPREPLY == *= ]] && compopt -o nospace + else + _cvs_entries + COMPREPLY=( $( compgen -W '${entries[@]:-}' -- "$cur" ) ) + fi + ;; + editors|watchers) + if [[ "$cur" = -* ]]; then + _cvs_command_options "$1" $mode + else + _cvs_entries + COMPREPLY=( $( compgen -W '${entries[@]}' -- "$cur" ) ) + fi + ;; export) case $prev in -r|-D) @@ -286,32 +302,7 @@ _cvs() COMPREPLY=( $( cvs -d "$cvsroot" co -c | awk '{print $1}' ) ) COMPREPLY=( $( compgen -W '${COMPREPLY[@]}' -- "$cur" ) ) else - COMPREPLY=( $( compgen -W "$( _cvs_command_options $mode )" \ - -- "$cur" ) ) - fi - ;; - diff) - if [[ "$cur" == -* ]]; then - _longopt diff - else - get_entries - COMPREPLY=( $( compgen -W '${entries[@]:-}' -- "$cur" ) ) - fi - ;; - remove) - if [[ "$cur" != -* ]]; then - set_prefix - if [[ $COMP_CWORD -gt 1 && -r ${prefix:-}CVS/Entries ]]; then - get_entries - # find out what files are missing - for i in "${entries[@]}"; do - [ ! -r "$i" ] && miss=( "${miss[@]}" $i ) - done - COMPREPLY=( $(compgen -W '${miss[@]:-}' -- "$cur") ) - fi - else - COMPREPLY=( $( compgen -W "$( _cvs_command_options $mode )" \ - -- "$cur" ) ) + _cvs_command_options "$1" $mode fi ;; import) @@ -328,9 +319,9 @@ _cvs() if [[ "$cur" != -* ]]; then # starts with same algorithm as checkout [ -z "$cvsroot" ] && cvsroot=$CVSROOT - prefix=${cur%/*} + local prefix=${cur%/*} if [ -r ${cvsroot}/${prefix} ]; then - get_modules + _cvs_modules COMPREPLY=( ${COMPREPLY[@]#$cvsroot} ) COMPREPLY=( ${COMPREPLY[@]#\/} ) fi @@ -338,8 +329,19 @@ _cvs() pwd=${pwd##*/} COMPREPLY=( $( compgen -W '${COMPREPLY[@]} $pwd' -- $cur ) ) else - COMPREPLY=( $( compgen -W "$( _cvs_command_options $mode )" \ - -- "$cur" ) ) + _cvs_command_options "$1" $mode + fi + ;; + remove) + if [[ "$cur" != -* ]]; then + _cvs_entries + # find out what files are missing + for i in "${entries[@]}"; do + [ ! -r "$i" ] && miss+=( $i ) + done + COMPREPLY=( $( compgen -W '${miss[@]:-}' -- "$cur" ) ) + else + _cvs_command_options "$1" $mode fi ;; update) @@ -354,8 +356,10 @@ _cvs() esac if [[ "$cur" = -* ]]; then - COMPREPLY=( $( compgen -W "$( _cvs_command_options $mode )" \ - -- "$cur" ) ) + _cvs_command_options "$1" $mode + else + _cvs_entries + COMPREPLY=( $( compgen -W '${entries[@]}' -- "$cur" ) ) fi ;; "") @@ -368,25 +372,19 @@ _cvs() return 0 ;; -z) - COMPREPLY=( $( compgen -W '1 2 3 4 5 6 7 8 9' -- "$cur" ) ) + COMPREPLY=( $( compgen -W '{1..9}' -- "$cur" ) ) return 0 ;; esac - COMPREPLY=( $( compgen -W '$( _cvs_commands ) $( _cvs_options ) \ + COMPREPLY=( $( compgen -W '$( _cvs_commands ) \ + $( _parse_help "$1" --help-options ) \ --help --help-commands --help-options --version' -- "$cur" ) ) ;; esac return 0 -} -complete -F _cvs -o default cvs -} +} && +complete -F _cvs cvs -# 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 |