[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 1.3-271-g5a6b9a2

Ville Skyttä ville.skytta at iki.fi
Wed May 4 21:20:31 UTC 2011


The following commit has been merged in the master branch:
commit 3334711726f4b8bba9e89db029c1ff7a1ad15160
Author: Ville Skyttä <ville.skytta at iki.fi>
Date:   Thu May 5 00:06:58 2011 +0300

    _parse_usage: Deal with whitespace in brackets.

diff --git a/bash_completion b/bash_completion
index 5012c11..29a2ed9 100644
--- a/bash_completion
+++ b/bash_completion
@@ -803,7 +803,7 @@ _parse_usage()
     local line match option i char
     "$cmd" ${2:---usage} 2>&1 | while read -r line; do
 
-        while [[ $line =~ \[(-[^]]+)\] ]]; do
+        while [[ $line =~ \[[[:space:]]*(-[^]]+)[[:space:]]*\] ]]; do
             match=${BASH_REMATCH[0]}
             option=${BASH_REMATCH[1]}
             case $option in
diff --git a/test/unit/_parse_usage.exp b/test/unit/_parse_usage.exp
index 6c7cd66..0069848 100644
--- a/test/unit/_parse_usage.exp
+++ b/test/unit/_parse_usage.exp
@@ -43,6 +43,14 @@ set cmd {fn() { printf '%s\n' "[--long/-s] [-S/--longer]"; }; _parse_usage fn}
 assert_bash_list "--long\n--longer" $cmd "long or short, slash"
 sync_after_int
 
+set cmd {fn() { printf '%s\n' "[ -a ] [ -b foo ]"; }; _parse_usage fn}
+assert_bash_list "-a\n-b" $cmd "whitespace in brackets"
+sync_after_int
+
+set cmd {fn() { printf '%s\n' "[ -a | --aa ]"; }; _parse_usage fn}
+assert_bash_list "--aa" $cmd "whitespace in brackets 2"
+sync_after_int
+
 set cmd {fn() { printf '%s\n' "----\n---foo\n----- bar"; }; _parse_usage fn}
 assert_bash_list "" $cmd "many dashes"
 sync_after_int

-- 
bash-completion



More information about the Bash-completion-commits mailing list