fix: trailing spaces

This commit is contained in:
Aloxaf 2026-03-14 22:02:35 +08:00
parent 9a3e06ebe9
commit b3c9068bd4
No known key found for this signature in database
GPG key ID: 0F8D23F44B277E02

View file

@ -9,15 +9,13 @@ local pid=$1 header_lines=$2 active_group_style=$3 tmp_dir=$4 offset=$5
# read completion list
local -a list=(${(f)mapfile[$tmp_dir/completions.$pid]})
local grep_cmd=${commands[grep]:-$commands[ggrep]}
# --- group marker detection (fzf-tab groups) ---------------------------------
# When groups exist, fzf-tab prefixes each entry with a group SGR like $'\e[94m'.
# When no groups exist (often file lists), entries may start with $'\e[0m'
# (reset for LS_COLORS). Treat that as "no groups".
local -Ua group_sgr_prefixes
if (( $#list > 10000 )) && [[ -n $grep_cmd ]]; then
group_sgr_prefixes=(${(f)"$(print -l -- ${list:$header_lines} | $grep_cmd -a -oP $'^\x1b\\[[0-9;]*m')"})
if (( $#list > 10000 && $+commands[grep] )); then
group_sgr_prefixes=(${(f)"$(print -l -- ${list:$header_lines} | command grep -a -o $'^\x1b\\[[0-9;]*m')"})
else
group_sgr_prefixes=(${(M)${list:$header_lines}#$'\x1b['[0-9;]#*m})
fi
@ -48,16 +46,16 @@ case $active_group_style in
esac
# The ANSI SGR code that marks every line in the currently selected group.
local current_prefix=${group_sgr_prefixes[current]}
local current_prefix=$group_sgr_prefixes[current]
# print headers
if (( header_lines != 0 )); then
# Apply style only to the group label (excluding trailing spaces), then disable it
print -l ${${list[1,header_lines]/(#b)($group_sgr_prefixes[current]*)( ##$'\x1b[00m')/$match[1]$sgr_off$match[2]}/${group_sgr_prefixes[current]}/$sgr_on}
print -l ${${(S)list[1,header_lines]/(#b)($current_prefix*)($'\x1b[00m')/${match[1]/%(#b)( #)/$sgr_off$match}$match[2]}/$current_prefix/$current_prefix$sgr_on}
fi
if (( $#list > 10000 )) && [[ -n $grep_cmd ]]; then
print -l -- ${list:$header_lines} | $grep_cmd -a -F -- "${group_sgr_prefixes[current]}"
if (( $#list > 10000 && $+commands[grep] )); then
print -l -- ${list:$header_lines} | command grep -a -F -- "${group_sgr_prefixes[current]}"
else
print -l -- ${(M)${list:$header_lines}:#${group_sgr_prefixes[current]}*}
fi