This commit is contained in:
Toni Kangas 2024-04-26 16:59:29 +02:00 committed by GitHub
commit be890a9c41
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -230,7 +230,7 @@ __%[1]s_handle_completion_types() {
comp=${comp%%%%$tab*} comp=${comp%%%%$tab*}
# Only consider the completions that match # Only consider the completions that match
if [[ $comp == "$cur"* ]]; then if [[ $comp == "$cur"* ]]; then
COMPREPLY+=("$comp") COMPREPLY+=( "$(printf %%q "$comp")" )
fi fi
done < <(printf "%%s\n" "${completions[@]}") done < <(printf "%%s\n" "${completions[@]}")
;; ;;
@ -247,7 +247,14 @@ __%[1]s_handle_standard_completion_case() {
# Short circuit to optimize if we don't have descriptions # Short circuit to optimize if we don't have descriptions
if [[ "${completions[*]}" != *$tab* ]]; then if [[ "${completions[*]}" != *$tab* ]]; then
IFS=$'\n' read -ra COMPREPLY -d '' < <(compgen -W "${completions[*]}" -- "$cur") local compgen_words=$(printf "%%s\n" "${completions[@]}")
IFS=$'\n' read -ra COMPREPLY -d '' < <(IFS=$'\n' compgen -W "${compgen_words}" -- "$cur")
# If there is a single completion left, escape the completion
if ((${#COMPREPLY[*]} == 1)); then
COMPREPLY[0]=$(printf %%q "${COMPREPLY[0]}")
fi
return 0 return 0
fi fi
@ -266,12 +273,12 @@ __%[1]s_handle_standard_completion_case() {
fi fi
done < <(printf "%%s\n" "${completions[@]}") done < <(printf "%%s\n" "${completions[@]}")
# If there is a single completion left, remove the description text # If there is a single completion left, remove the description text and escape the completion
if ((${#COMPREPLY[*]} == 1)); then if ((${#COMPREPLY[*]} == 1)); then
__%[1]s_debug "COMPREPLY[0]: ${COMPREPLY[0]}" __%[1]s_debug "COMPREPLY[0]: ${COMPREPLY[0]}"
comp="${COMPREPLY[0]%%%%$tab*}" comp="${COMPREPLY[0]%%%%$tab*}"
__%[1]s_debug "Removed description from single completion, which is now: ${comp}" __%[1]s_debug "Removed description from single completion, which is now: ${comp}"
COMPREPLY[0]=$comp COMPREPLY[0]=$(printf %%q "${comp}")
else # Format the descriptions else # Format the descriptions
__%[1]s_format_comp_descriptions $longest __%[1]s_format_comp_descriptions $longest
fi fi