Add _split_longopt() helper for improved handling of long options that take arguments in both "--foo bar" and "--foo=bar" formats.

This commit is contained in:
Ville Skyttä 2009-04-14 23:16:47 +03:00
parent a66323a18f
commit 45182e1809
2 changed files with 19 additions and 0 deletions

View File

@ -32,6 +32,8 @@ bash-completion (1.x)
* Use POSIX compliant arguments to tail in mkisofs completion.
* Protect various completions from unusual user input by not embedding the
input in external command arguments.
* Add _split_longopt() helper for improved handling of long options that
take arguments in both "--foo bar" and "--foo=bar" formats.
[ Todd Zullinger ]
* Make yum complete on filenames after install, deplist, update and upgrade

View File

@ -317,6 +317,23 @@ _filedir()
COMPREPLY=( "${COMPREPLY[@]}" "${toks[@]}" )
}
# This function splits $cur=--foo=bar into $prev=--foo, $cur=bar, making it
# easier to support both "--foo bar" and "--foo=bar" style completions.
# Returns 0 if current option was split, 1 otherwise.
#
_split_longopt()
{
if [[ "$cur" == --?*=* ]]; then
# Cut also backslash before '=' in case it ended up there
# for some reason.
prev="${cur%%?(\\)=*}"
cur="${cur#*=}"
return 0
fi
return 1
}
# This function tries to parse the output of $command --help
#
_parse_help() {