]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei: completion: bash: generalize nospace usage
authorEric Wong <e@80x24.org>
Thu, 18 Feb 2021 12:27:09 +0000 (18:27 +0600)
committerEric Wong <e@80x24.org>
Fri, 19 Feb 2021 00:02:07 +0000 (20:02 -0400)
We'll be completing more options with ':', '//' and '=' in the
future, so make it easier to disable trailing spaces on
completions.

contrib/completion/lei-completion.bash

index 619805fbe2b2f656f1f59d499a4ba232113f9328..2c28d44a56463ab4e56f71fe02d51ae041e19502 100644 (file)
@@ -4,14 +4,12 @@
 # preliminary bash completion support for lei (Local Email Interface)
 # Needs a lot of work, see `lei__complete' in lib/PublicInbox::LEI.pm
 _lei() {
-       case ${COMP_WORDS[@]} in
-       *' add-external h'* | *' --mirror h'*)
-               compopt -o nospace
-               ;;
+       local wordlist="$(lei _complete ${COMP_WORDS[@]})"
+       case $wordlist in
+       *':'* | *'='* | '//'*) compopt -o nospace ;;
        *) compopt +o nospace ;; # the default
        esac
-       COMPREPLY=($(compgen -W "$(lei _complete ${COMP_WORDS[@]})" \
-                       -- "${COMP_WORDS[COMP_CWORD]}"))
+       COMPREPLY=($(compgen -W "$wordlist" -- "${COMP_WORDS[COMP_CWORD]}"))
        return 0
 }
 complete -o default -o bashdefault -F _lei lei