tmux-grab: fix floating pane closing immediately on Tab
tmux-grab crashed under set -u because IN_TMUX_FLOAT=1 (always set by
the Tab binding) leaves tmux_opts as an empty array, and
"${tmux_opts[@]}" on an empty array throws "unbound variable" on
macOS bash 3.2 (Apple last GPLv2 release, frozen since 2007 — the bug
was fixed in bash 4.4). new-pane has no remain-on-exit, so the pane
closed before the error was visible. Switched to the nounset-safe
"${arr[@]+"${arr[@]}"}" expansion, which handles both empty and
populated arrays.
Also swaps tac for tail -r, since macOS does not ship GNU tac.
Assisted-by: Claude Sonnet 5 via Claude Code
diff --git a/bin/,tmux-grab b/bin/,tmux-grab
index 5deb8fd3..5d08cafc 100755
--- a/bin/,tmux-grab
+++ b/bin/,tmux-grab
@@ -15,7 +15,7 @@ main() {
# tac reverses line order so the most recent scrollback surfaces first in
# the fzf list, while keeping left-to-right token order within each line.
local pane_text
- pane_text=$(tmux capture-pane -p -S - -t "$pane_id" | tac)
+ pane_text=$(tmux capture-pane -p -S - -t "$pane_id" | tail -r)
[[ -n "$pane_text" ]] || exit 0
# Two passes: whitespace-delimited tokens first (so "foo/bar:baz" is a
@@ -42,8 +42,11 @@ main() {
# line of output, empty unless ctrl-y/ctrl-o was the trigger, with the
# selected token on the following line.
local result
+ # macOS ships bash 3.2 (last GPLv2 release); under set -u, "${arr[@]}"
+ # on an empty array throws "unbound variable" there (fixed in bash 4.4).
+ # The +"${arr[@]}" form works around it for both empty and populated arrays.
result=$(printf '%s\n' "$tokens" | FZF_DEFAULT_OPTS='' fzf --no-multi --select-1 --no-margin --no-padding \
- "${tmux_opts[@]}" \
+ "${tmux_opts[@]+"${tmux_opts[@]}"}" \
--layout reverse \
--height 100% \
--highlight-line --info inline-right \