[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 1.3-320-gf186fc0

Ville Skyttä ville.skytta at iki.fi
Tue May 24 20:13:33 UTC 2011


The following commit has been merged in the master branch:
commit af3f67f2e5f593e5c6ea7958cce2d8c268ec41bc
Author: Ville Skyttä <ville.skytta at iki.fi>
Date:   Tue May 24 23:08:45 2011 +0300

    cvs: Improve CVS controlled file completions.

diff --git a/completions/cvs b/completions/cvs
index 85b9467..0a9d1d3 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 0000000..6462f98
--- /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/acroread/bar b/test/fixtures/cvs/foo/bar
similarity index 100%
copy from test/fixtures/acroread/bar
copy to test/fixtures/cvs/foo/bar
diff --git a/test/fixtures/_filedir/a b/i b/test/fixtures/cvs/foo/quux
similarity index 100%
copy from test/fixtures/_filedir/a b/i
copy to test/fixtures/cvs/foo/quux
diff --git a/test/lib/completions/cvs.exp b/test/lib/completions/cvs.exp
index 3b2643d..9248edc 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

-- 
bash-completion



More information about the Bash-completion-commits mailing list