diff --git a/completions/cvs b/completions/cvs index 85b94675..0a9d1d39 100644 --- a/completions/cvs +++ b/completions/cvs @@ -2,17 +2,15 @@ have cvs || return -set_prefix() -{ - [ -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() @@ -55,7 +53,7 @@ _cvs() local cur prev words cword _init_completion -n : || return - local count mode i cvsroot cvsroots pwd prefix + local count mode i cvsroot cvsroots pwd local -a flags miss files entries changed newremoved count=0 @@ -149,17 +147,24 @@ _cvs() esac if [[ "$cur" != -* ]]; then - set_prefix - if [[ $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 + get_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 @@ -228,9 +233,7 @@ _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 @@ -289,15 +292,12 @@ _cvs() ;; remove) if [[ "$cur" != -* ]]; then - set_prefix - if [[ $cword -gt 1 && -r ${prefix:-}CVS/Entries ]]; then - get_entries - # find out what files are missing - for i in "${entries[@]}"; do - [ ! -r "$i" ] && miss+=( $i ) - done - COMPREPLY=( $(compgen -W '${miss[@]:-}' -- "$cur") ) - fi + get_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 @@ -316,7 +316,7 @@ _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 COMPREPLY=( ${COMPREPLY[@]#$cvsroot} ) diff --git a/test/fixtures/cvs/foo/CVS/Entries b/test/fixtures/cvs/foo/CVS/Entries new file mode 100644 index 00000000..6462f980 --- /dev/null +++ b/test/fixtures/cvs/foo/CVS/Entries @@ -0,0 +1,2 @@ +/bar/1.1/Tue Jan 29 05:52:29 2008// +D diff --git a/test/fixtures/cvs/foo/bar b/test/fixtures/cvs/foo/bar new file mode 100644 index 00000000..e69de29b diff --git a/test/fixtures/cvs/foo/quux b/test/fixtures/cvs/foo/quux new file mode 100644 index 00000000..e69de29b diff --git a/test/lib/completions/cvs.exp b/test/lib/completions/cvs.exp index 3b2643d3..9248edc8 100644 --- a/test/lib/completions/cvs.exp +++ b/test/lib/completions/cvs.exp @@ -8,6 +8,7 @@ proc teardown {} { assert_bash_exec {HOME=$OLDHOME} assert_env_unmodified { /OLDHOME=/d + /OLDPWD=/d } } @@ -33,4 +34,8 @@ expect { sync_after_int +assert_complete_dir "foo/bar" "cvs diff foo/" $::srcdir/fixtures/cvs +sync_after_int + + teardown