Skip to content

Commit 0ad4153

Browse files
committed
refactor(openssl): reduce redundant splitting
The current code performs the splitting twice: the output of a command is first split by IFS, second joined by \n while adding the prefix `-`, and then again split by IFS, which is redundant. We may directly split the output by `_comp_compgen_split` while adding the prefix using the `-P` option.
1 parent 42877e4 commit 0ad4153

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

completions/openssl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ _comp_cmd_openssl__compgen_sections()
2727

2828
_comp_cmd_openssl__compgen_digests()
2929
{
30+
[[ $cur == -* ]] || return
3031
_comp_compgen_split -- "$(
3132
"$1" dgst -h 2>&1 |
3233
_comp_awk '/^-.*[ \t]to use the .* message digest algorithm/ { print $1 }'
33-
local -a digests=($("$1" help 2>&1 |
34-
command sed -ne '/^Message Digest commands/,/^[[:space:]]*$/p' |
35-
command sed -e 1d))
36-
printf "%s\n" "${digests[@]/#/-}"
3734
)"
35+
_comp_compgen -ac "${cur#-}" split -P "-" -- "$("$1" help 2>&1 |
36+
command sed -ne '/^Message Digest commands/,/^[[:space:]]*$/p' |
37+
command sed -e 1d)"
3838
}
3939

4040
_comp_cmd_openssl()

0 commit comments

Comments
 (0)