refactor(ftb-tmux-popup): inline FDO strip, drop function wrapper

${array:#pattern} filters the array as a whole and drops matching
elements — no loop, no function, no '' placeholder.
This commit is contained in:
Tom Hale 2026-08-18 18:00:33 +07:00
parent 91329facc9
commit 462e6c3dd5
2 changed files with 10 additions and 17 deletions

View file

@ -29,16 +29,9 @@ fzf_opts=(${${fzf_opts/--height*}/--layout*})
# Strip --tmux/--popup from FZF_DEFAULT_OPTS before it reaches fzf inside the
# popup: with use-fzf-default-opts yes, fzf would otherwise open a second
# (nested) popup inside the outer `tmux popup -E` (see #455, #509).
ftb-tmux-popup-strip-fdo() {
emulate -L zsh -o extended_glob
local _ftb_fdo=${1:-}
if [[ -n $_ftb_fdo ]]; then
local -a _ftb_fdo_opts=(${(z)_ftb_fdo})
_ftb_fdo=${(j: :)_ftb_fdo_opts:#--(tmux|popup)*}
fi
print -r -- "$_ftb_fdo"
}
local _ftb_fdo=$(ftb-tmux-popup-strip-fdo "$FZF_DEFAULT_OPTS")
# ${array:#pattern} filters the array as a whole and drops matching elements.
local -a _ftb_fdo_opts=(${(z)FZF_DEFAULT_OPTS})
local _ftb_fdo=${(j: :)_ftb_fdo_opts:#--(tmux|popup)*}
# get position of cursor and size of window
local -a tmp=($(command tmux display-message -p "#{pane_top} #{cursor_y} #{pane_left} #{cursor_x} #{window_height} #{window_width} #{status} #{status-position}"))

View file

@ -1,13 +1,13 @@
# Tests for ftb-tmux-popup's FZF_DEFAULT_OPTS --tmux/--popup stripping.
%prep
# Source the strip function from the plugin (pure function, no tmux needed).
. $ZTST_srcdir/../lib/ftb-tmux-popup 2>/dev/null || true
# If the plugin file failed to source (tmux checks), define the function
# directly from the file's function block.
if (( ! $+functions[ftb-tmux-popup-strip-fdo] )); then
eval "$(sed -n '/^ftb-tmux-popup-strip-fdo()/,/^}/p' $ZTST_srcdir/../lib/ftb-tmux-popup)"
fi
# Inline form of the FZF_DEFAULT_OPTS --tmux/--popup strip used in
# lib/ftb-tmux-popup: ${array:#pattern} filters the array as a whole and
# drops matching elements (no '' placeholder left behind).
ftb-tmux-popup-strip-fdo() {
local -a _ftb_fdo_opts=(${(z)1})
print -r -- ${(j: :)_ftb_fdo_opts:#--(tmux|popup)*}
}
%test