diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2018-12-07 01:01:49 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2018-12-07 01:01:49 +1300 |
commit | b54303b509d30e21679e0032e0875300c7b8b7dc (patch) | |
tree | e23d32e2d877f7c4dc4e2c32d82a7bb30ebc3e89 /bash/bash_completion.d/openssl.bash | |
parent | Remove unneeded stdout redirect (diff) | |
download | dotfiles-b54303b509d30e21679e0032e0875300c7b8b7dc.tar.gz dotfiles-b54303b509d30e21679e0032e0875300c7b8b7dc.zip |
Refactor some completions to avoid loops
Diffstat (limited to 'bash/bash_completion.d/openssl.bash')
-rw-r--r-- | bash/bash_completion.d/openssl.bash | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/bash/bash_completion.d/openssl.bash b/bash/bash_completion.d/openssl.bash index 1cb4bd07..b1f13103 100644 --- a/bash/bash_completion.d/openssl.bash +++ b/bash/bash_completion.d/openssl.bash @@ -8,25 +8,18 @@ _openssl() { ((COMP_CWORD == 1)) || return # Iterate through completions produced by subshell + local -a subcmds local ci comp - while read -r comp ; do - COMPREPLY[ci++]=$comp + while read -a subcmds -r ; do + for subcmd in "${subcmds[@]}" ; do + case $subcmd in + "$2"*) COMPREPLY[ci++]=$comp ;; + esac + done 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 - done - } + openssl list -commands \ + -cipher-commands \ + -digest-commands ) } complete -F _openssl -o bashdefault -o default openssl |