[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 1.3-273-g2d23a3f

Ville Skyttä ville.skytta at iki.fi
Sun May 8 12:26:52 UTC 2011


The following commit has been merged in the master branch:
commit 2d23a3f47ca18aa2c06cda010c32b1611e98c539
Author: Ville Skyttä <ville.skytta at iki.fi>
Date:   Sun May 8 14:46:12 2011 +0300

    ant: Rewrite build target parsing in plain bash, add build file test case.
    
    There's no alternation (\|) in POSIX basic regexps which is what POSIX
    sed supports.

diff --git a/completions/ant b/completions/ant
index 79970da..80f8de6 100644
--- a/completions/ant
+++ b/completions/ant
@@ -50,11 +50,13 @@ _ant()
         [ ! -f $buildfile ] && return 0
 
         # parse buildfile for targets
-        # some versions of sed complain if there's no trailing linefeed,
-        # hence the 2>/dev/null
-        COMPREPLY=( $( compgen -W "$( tr "'\t\n>" "\"  \n" < $buildfile | \
-            sed -ne 's/.*<\(target\|extension-point\) .*name="\([^"]*\).*/\2/p' 2>/dev/null )" \
-            -- "$cur" ) )
+        local line targets
+        while read -rd '>' line; do
+            [[ $line =~ \
+               \<(targe|extension-poin)t[[:space:]].*name=[\"\']([^\"\']+) ]] \
+                && targets+=" ${BASH_REMATCH[2]}"
+        done < $buildfile
+        COMPREPLY=( $( compgen -W '$targets' -- "$cur" ) )
     fi
 } &&
 have ant && { have complete-ant-cmd.pl && \
diff --git a/test/fixtures/ant/build.xml b/test/fixtures/ant/build.xml
new file mode 100644
index 0000000..146c7f3
--- /dev/null
+++ b/test/fixtures/ant/build.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project basedir="." default="build" name="bash-completion">
+    <target name="clean">
+        <!-- ... -->
+    </target>
+<target
+    name="realclean" depends="clean">
+    <!-- ... -->
+	</target>
+
+	<target foo="bar" name="init"></target>
+<target
+foo="bar"
+name='bashcomp' >
+<!-- ... -->
+</target>
+</project>
diff --git a/test/lib/completions/ant.exp b/test/lib/completions/ant.exp
index de57f24..a5f022a 100644
--- a/test/lib/completions/ant.exp
+++ b/test/lib/completions/ant.exp
@@ -4,7 +4,10 @@ proc setup {} {
 
 
 proc teardown {} {
-    assert_env_unmodified
+    assert_env_unmodified {
+        /OLDPWD=/d
+        /BASH_REMATCH=/d
+    }
 }
 
 
@@ -12,8 +15,10 @@ setup
 
 
 assert_complete_any "ant -"
+sync_after_int
 
 
+assert_complete_dir "bashcomp clean init realclean" "ant " $::srcdir/fixtures/ant
 sync_after_int
 
 

-- 
bash-completion



More information about the Bash-completion-commits mailing list