diff --git a/CHANGES b/CHANGES index 78e8d766..c424bd7e 100644 --- a/CHANGES +++ b/CHANGES @@ -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 diff --git a/bash_completion b/bash_completion index b01eba57..07827fb5 100644 --- a/bash_completion +++ b/bash_completion @@ -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() {