maint(_chroma/-ssh.ch): don't expand $userdirs for user matching

`$userdirs` can be pretty huge, and blindly expanding it to match as a regex expression
can be expensive.

Because `$userdirs` is an associative array, leveraging direct member lookup is the optimal method.
This commit is contained in:
vladislav doster 2022-02-27 21:55:37 -05:00 committed by GitHub
commit 35556c2f83
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -25,7 +25,7 @@ setopt extended_glob warn_create_global typeset_silent
local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4"
local __style check_port=0 host_start_offset host_style user_style possible_host
local -a match mbegin mend completions_user completions_host
local -a match mbegin mend completions_users completions_host
# First call, i.e. command starts, i.e. "grep" token etc.
(( __first_call )) && {
@ -70,11 +70,14 @@ local -a match mbegin mend completions_user completions_host
# Zstyle clobbers reply for sure
zstyle -a ":completion:*:users" users completions_users
}
(( ! $#completions_users )) && completions_users=(${(k)userdirs})
if (( $#completions_users )); then
[[ $match[2] = ${~${:-(${(j:|:)completions_users})}} ]] \
&& user_style=${FAST_THEME_NAME}correct-subtle \
|| user_style=${FAST_THEME_NAME}incorrect-subtle
elif (( $#userdirs )); then
[[ -n $userdirs[$match[2]] ]] \
&& user_style=${FAST_THEME_NAME}correct-subtle \
|| user_style=${FAST_THEME_NAME}incorrect-subtle
fi
[[ -n $user_style ]] \
&& (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}-(mend[5]-mend[2]), __start >= 0 )) \