[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 1.3-135-g3a39ac6

Ville Skyttä ville.skytta at iki.fi
Wed Apr 27 15:41:58 UTC 2011


The following commit has been merged in the master branch:
commit 5cd5993211818e4c46367abd78c70a02b04458ca
Author: Ville Skyttä <ville.skytta at iki.fi>
Date:   Wed Apr 27 15:29:00 2011 +0300

    _parse_help: Change to output first long option, or first short if not found.
    
    Makes things more consistent with the rest of our option offerings.

diff --git a/CHANGES b/CHANGES
index 0016003..ff7fb74 100644
--- a/CHANGES
+++ b/CHANGES
@@ -3,7 +3,7 @@ bash-completion (2.x)
   [ Ville Skyttä ]
   * Add pxz and reptyr completions.
   * Improve aspell, gendiff, rsync, screen, smartctl, tar, xz, xzdec, and
-    generic long option completions.
+    generic parsed and long option completions.
   * Try harder to find the correct perl executable to run the perl helper with.
   * Drop rpm query support for rpm < 4.1.
   * Split rpm and rpmbuild completions and improve them both.
diff --git a/bash_completion b/bash_completion
index fe01ac2..feb520b 100644
--- a/bash_completion
+++ b/bash_completion
@@ -747,8 +747,20 @@ _init_completion()
 #
 _parse_help()
 {
-    $1 ${2:---help} 2>&1 | sed -e '/^[[:space:]]*-/!d' -e 's|[,/]| |g' | \
-        awk '{ print $1; if ($2 ~ /^-/) { print $2 } }' | sed -e 's|[<=[].*||'
+    # Print first found long option, or first short if not found.
+    $1 ${2:---help} 2>&1 | awk \
+        '{
+             if ($0 !~ /^[ \t]*-/) { next }
+             gsub("[,/]", " ");
+             x = -1;
+             for (i = 1; i <= NF; i++) {
+                 if (sub("^(--.[^<[]*)", "&", $i)) { x = i ; break }
+                 if ($i !~ /^-/) { break }
+             }
+             if (x == -1) { x = 1 }
+             sub("=.*", "", $x);
+             print $x
+         }'
 }
 
 # This function completes on signal names
diff --git a/test/unit/_parse_help.exp b/test/unit/_parse_help.exp
index 4beb28d..2c95032 100644
--- a/test/unit/_parse_help.exp
+++ b/test/unit/_parse_help.exp
@@ -38,11 +38,11 @@ assert_bash_list "-space" $cmd "one dash after space"
 sync_after_int
 
 set cmd {fn() { printf '%s\n' "-one -two dashes"; }; _parse_help fn}
-assert_bash_list "-one\n-two" $cmd "two dashes, space-separated"
+assert_bash_list "-one" $cmd "two dashes, space-separated"
 sync_after_int
 
 set cmd {fn() { printf '%s\n' "-one,-t dashes"; }; _parse_help fn}
-assert_bash_list "-one\n-t" $cmd "two dashes, comma-separated"
+assert_bash_list "-one" $cmd "two dashes, comma-separated"
 sync_after_int
 
 set cmd {fn() { printf '%s\n' "-one dash-inside"; }; _parse_help fn}
@@ -58,15 +58,19 @@ assert_bash_list "--long-arg" $cmd "value not seen as option"
 sync_after_int
 
 set cmd {fn() { printf '%s\n' "--long-arg=-value,--opt2=val"; }; _parse_help fn}
-assert_bash_list "--long-arg\n--opt2" $cmd "two options with values"
+assert_bash_list "--long-arg" $cmd "two options with values"
 sync_after_int
 
 set cmd {fn() { printf '%s\n' "-m,--mirror"; }; _parse_help fn}
-assert_bash_list "-m\n--mirror" $cmd "short + long"
+assert_bash_list "--mirror" $cmd "short + long"
 sync_after_int
 
 set cmd {fn() { printf '%s\n' "-T/--upload-file"; }; _parse_help fn}
-assert_bash_list "-T\n--upload-file" $cmd "short + long, slash separated"
+assert_bash_list "--upload-file" $cmd "short + long, slash separated"
+sync_after_int
+
+set cmd {fn() { printf '%s\n' "-f, -F, --foo"; }; _parse_help fn}
+assert_bash_list "--foo" $cmd "short + short + long"
 sync_after_int
 
 

-- 
bash-completion



More information about the Bash-completion-commits mailing list