diff --git a/bash_completion.d/cluset b/bash_completion.d/cluset index e5775074..db7b73fd 100644 --- a/bash_completion.d/cluset +++ b/bash_completion.d/cluset @@ -41,6 +41,35 @@ _cluset() case "$prev" in -c|--count|-e|--expand|-f|--fold|\ -x|--exclude|-i|--intersection|-X|--xor) + local orig="$cur" + # split words (by ,-not-in-brackets and &) + # Note completions with & are mostly borked + while true; do + case "$cur" in + *"&"*) + # cannot handle & without some bash-completion-fu, + # because it tries to simplify &'s escaping and then + # fails as that splits commands... Just give up. + return + ;; + *"["*"]"*,*) + # complete set, remove one word + cur="${cur#*,}" + ;; + *"["*) + # open bracket: leave as is + break + ;; + *,*) + # no brackets, remove one word + cur="${cur#*,}" + ;; + *) + # nothing left to do + break + ;; + esac + done case "$cur" in *:*) groupsource="${cur%%:*}" @@ -56,6 +85,11 @@ _cluset() if [ -n "$cleangroup" ]; then options=${options//@"$groupsource":/@} fi + if [ "$orig" != "$cur" ]; then + local prefix=${orig%$cur} + options="$prefix${options//$'\n'/&"$prefix"}" + cur="$orig" + fi ;; -s|--groupsource) options=$(cluset --groupsources --quiet) diff --git a/bash_completion.d/clush b/bash_completion.d/clush index 46474d24..55e6db92 100644 --- a/bash_completion.d/clush +++ b/bash_completion.d/clush @@ -40,6 +40,35 @@ _clush() case "$prev" in -w|-x|-g|--group|-X) + local orig="$cur" + # split words (by ,-not-in-brackets and &) + # Note completions with & are mostly borked + while true; do + case "$cur" in + *"&"*) + # cannot handle & without some bash-completion-fu, + # because it tries to simplify &'s escaping and then + # fails as that splits commands... Just give up. + return + ;; + *"["*"]"*,*) + # complete set, remove one word + cur="${cur#*,}" + ;; + *"["*) + # open bracket: leave as is + break + ;; + *,*) + # no brackets, remove one word + cur="${cur#*,}" + ;; + *) + # nothing left to do + break + ;; + esac + done case "$cur" in *:*) groupsource="${cur%%:*}" @@ -63,6 +92,11 @@ _clush() options=${options//@/} ;; esac + if [ "$orig" != "$cur" ]; then + local prefix=${orig%$cur} + options="$prefix${options//$'\n'/&"$prefix"}" + cur="$orig" + fi ;; -s|--groupsource) options=$(cluset --groupsources --quiet)