diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2018-12-02 17:59:29 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2018-12-02 17:59:29 +1300 |
commit | 7d6fe8b1886f902f8ffbec2a9985fae9f91121cb (patch) | |
tree | 282fac0bb1809e726a373916c90260832ab23ced /bash/bash_completion.d/openssl.bash | |
parent | Reduce ud() completion to just dirnames (diff) | |
download | dotfiles-7d6fe8b1886f902f8ffbec2a9985fae9f91121cb.tar.gz dotfiles-7d6fe8b1886f902f8ffbec2a9985fae9f91121cb.zip |
Overhaul Bash completion scripts
Some general changes:
* Apply case sensitivity switching in more contexts, using a dynamically
loaded helper function
* Use array counters for appending to COMPREPLY where possible
* Lots more short-circuiting to limit structural depth
These changes are expansive and there will definitely be bugs.
Diffstat (limited to 'bash/bash_completion.d/openssl.bash')
-rw-r--r-- | bash/bash_completion.d/openssl.bash | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/bash/bash_completion.d/openssl.bash b/bash/bash_completion.d/openssl.bash index 3396eb9f..1cb4bd07 100644 --- a/bash/bash_completion.d/openssl.bash +++ b/bash/bash_completion.d/openssl.bash @@ -1,26 +1,32 @@ # Some simple completion for openssl(1ssl) _openssl() { + # Needs openssl(1ssl) + hash openssl 2>/dev/null || return + # Only complete the first word: OpenSSL subcommands - case $COMP_CWORD in - 1) - while read -r subcmd ; do - case $subcmd in - '') ;; - "$2"*) - COMPREPLY[${#COMPREPLY[@]}]=$subcmd - ;; - esac - done < <( - for arg in \ - list-cipher-commands \ - list-standard-commands \ - list-message-digest-commands ; do - printf '%s\n' "$arg" - openssl "$arg" + ((COMP_CWORD == 1)) || return + + # Iterate through completions produced by subshell + local ci comp + while read -r comp ; do + COMPREPLY[ci++]=$comp + done < <( + + # Run each of the command-listing commands; read each line into an + # array of subcommands (they are printed as a table) + for list in commands digest-commands cipher-commands ; do + openssl list -"$list" + done | { + declare -a subcmds + while read -a subcmds -r ; do + for subcmd in "${subcmds[@]}" ; do + case $subcmd in + ("$2"*) printf '%s\n' "$subcmd" ;; + esac done - ) - ;; - esac + done + } + ) } complete -F _openssl -o bashdefault -o default openssl |