diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-19 13:14:52 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-19 13:14:52 -0500 |
| commit | 95e1e0be4905ff5d37b52f889f5dda65543e2b51 (patch) | |
| tree | e3a185caad1ecfba557e85c7d2c3eb66344a9f00 /tests/tmux-util/fake-fzf | |
| parent | 331d9421f1ca56afdaf0d238082f83d82103a795 (diff) | |
| download | archsetup-95e1e0be4905ff5d37b52f889f5dda65543e2b51.tar.gz archsetup-95e1e0be4905ff5d37b52f889f5dda65543e2b51.zip | |
feat(tmux-util): add pick subcommand (fzf session switcher)
tmux-util pick lists every session ("attached"/"detached" plus name), pipes it through fzf, and attaches or switch-clients to the chosen one (matching the go subcommand's inside-vs-outside-tmux discipline).
If the user cancels fzf (Ctrl-C, Esc, empty selection), the pipeline returns empty and pick exits 0 without touching tmux state.
The new fake-fzf testing fake is driven by env vars:
- FAKE_FZF_CHOICE_LINE=<N>: return the Nth line of stdin as the selection
- FAKE_FZF_CHOICE=<string>: return the literal string (ignores stdin)
- (neither): exit 130 to simulate cancel
4 new tests cover Normal cases (pick second line, inside/outside tmux behavior) and Boundary cases (no sessions, user cancellation). Total suite: 43 tests, all green.
Diffstat (limited to 'tests/tmux-util/fake-fzf')
| -rwxr-xr-x | tests/tmux-util/fake-fzf | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/tmux-util/fake-fzf b/tests/tmux-util/fake-fzf new file mode 100755 index 0000000..476bf7f --- /dev/null +++ b/tests/tmux-util/fake-fzf @@ -0,0 +1,30 @@ +#!/bin/sh +# Fake fzf for testing tmux-util. +# +# Control via env vars: +# FAKE_FZF_CHOICE_LINE — 1-based line index into stdin; that line is +# printed as the selection and exit 0. +# FAKE_FZF_CHOICE — print this literal string as the selection and +# exit 0 (ignored if FAKE_FZF_CHOICE_LINE is set). +# (neither set) — exit 130 (user cancelled). +# +# Every invocation is logged to $FAKE_TMUX_DIR/calls.log as one line. + +: "${FAKE_TMUX_DIR:?FAKE_TMUX_DIR must be set}" +printf 'fzf %s\n' "$*" >> "$FAKE_TMUX_DIR/calls.log" + +if [ -n "${FAKE_FZF_CHOICE_LINE:-}" ]; then + awk -v n="$FAKE_FZF_CHOICE_LINE" 'NR == n { print; exit }' + exit 0 +fi + +if [ -n "${FAKE_FZF_CHOICE:-}" ]; then + # Drain stdin so the pipe upstream doesn't SIGPIPE + cat >/dev/null + printf '%s\n' "$FAKE_FZF_CHOICE" + exit 0 +fi + +# Cancelled +cat >/dev/null +exit 130 |
