diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-19 13:17:06 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-19 13:17:06 -0500 |
| commit | f91586248f467a2ba7a62f76caee1f40927655d9 (patch) | |
| tree | 39ff6ae73fa53f8164c0a8ad104dc550313cad44 /tests/tmux-util/fake-tmux | |
| parent | 95e1e0be4905ff5d37b52f889f5dda65543e2b51 (diff) | |
| download | archsetup-f91586248f467a2ba7a62f76caee1f40927655d9.tar.gz archsetup-f91586248f467a2ba7a62f76caee1f40927655d9.zip | |
feat(tmux-util): add rename subcommand (fzf pick + prompt)
tmux-util rename closes out the original six-subcommand plan. The flow:
1. fzf-pick a session from the list.
2. Prompt for a new name on stdin.
3. Bail with a useful message on empty input, same-as-old, or conflict with an existing session.
4. Otherwise `tmux rename-session -t <old> <new>` and confirm.
The conflict check uses `tmux has-session -t =<new>` with the same `=`-prefix exact-match guard as the go subcommand. Without it, tmux's default prefix matching would let `rename foo` succeed even when a session named `foobar` already exists, then surprise the user later.
5 new tests cover Normal cases (pick + rename happy path) and Boundary cases (no sessions, fzf cancel, empty new name, same-as-old no-op, conflict with existing session). The test harness's run_script grew an `stdin=` param so tests can feed the prompt input. fake-tmux picked up a rename-session handler that mutates the state file. Total suite: 48 tests, all green.
Six subcommands shipped: go, pick, ls, find, reap, rename. The original "no args prints help" requirement still holds, and the stub-test for unimplemented subcommands got removed since everything's wired now.
Diffstat (limited to 'tests/tmux-util/fake-tmux')
| -rwxr-xr-x | tests/tmux-util/fake-tmux | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/tmux-util/fake-tmux b/tests/tmux-util/fake-tmux index b5a1e61..1b84956 100755 --- a/tests/tmux-util/fake-tmux +++ b/tests/tmux-util/fake-tmux @@ -151,6 +151,34 @@ case "$cmd" in attach-session|switch-client) # No state mutation needed — the call log already records intent. ;; + rename-session) + # Forms: rename-session -t <old> <new> OR rename-session <new> + old="" + new="" + while [ "$#" -gt 0 ]; do + case "$1" in + -t) shift; old="$1"; shift ;; + *) new="$1"; shift ;; + esac + done + if [ -z "$old" ] || [ -z "$new" ]; then + echo "fake-tmux rename-session: need both -t <old> and <new>" >&2 + exit 1 + fi + tmp="$STATE.tmp" + : > "$tmp" + while IFS= read -r line; do + [ -n "$line" ] || continue + first="${line%% *}" + rest="${line#* }" + if [ "$first" = "$old" ]; then + printf '%s %s\n' "$new" "$rest" >> "$tmp" + else + printf '%s\n' "$line" >> "$tmp" + fi + done < "$STATE" + mv "$tmp" "$STATE" + ;; kill-session) session="" while [ "$#" -gt 0 ]; do |
