_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.
This commit is contained in:
parent
7b2c2ebf9b
commit
5cd5993211
2
CHANGES
2
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.
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user