From f91586248f467a2ba7a62f76caee1f40927655d9 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Tue, 19 May 2026 13:17:06 -0500 Subject: 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 ` and confirm. The conflict check uses `tmux has-session -t =` 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. --- dotfiles/common/.local/bin/tmux-util | 50 ++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) (limited to 'dotfiles') diff --git a/dotfiles/common/.local/bin/tmux-util b/dotfiles/common/.local/bin/tmux-util index 4669b03..dca01fd 100755 --- a/dotfiles/common/.local/bin/tmux-util +++ b/dotfiles/common/.local/bin/tmux-util @@ -35,6 +35,53 @@ Run with no arguments to print this help. EOF } +# ----------------------------------------------------------------------------- +# rename +# ----------------------------------------------------------------------------- + +cmd_rename() { + local sessions + sessions=$(tmux list-sessions \ + -F '#{session_attached} #{session_name}' 2>/dev/null || true) + if [ -z "$sessions" ]; then + echo "No tmux sessions to rename." + return 0 + fi + + local choice + choice=$(echo "$sessions" | awk '{ + state = ($1 == "1") ? "attached" : "detached" + printf "%-9s %s\n", state, $2 + }' | fzf --header="Pick a session to rename" | awk '{print $2}') + + if [ -z "$choice" ]; then + # User cancelled. + return 0 + fi + + local new_name + printf 'New name for "%s": ' "$choice" + read -r new_name + + if [ -z "$new_name" ]; then + echo "tmux-util rename: empty new name, cancelled." >&2 + return 1 + fi + + if [ "$new_name" = "$choice" ]; then + echo "tmux-util rename: new name same as old, no change." + return 0 + fi + + if tmux has-session -t "=$new_name" 2>/dev/null; then + echo "tmux-util rename: a session named '$new_name' already exists." >&2 + return 1 + fi + + tmux rename-session -t "$choice" "$new_name" + echo "Renamed: $choice -> $new_name" +} + # ----------------------------------------------------------------------------- # pick # ----------------------------------------------------------------------------- @@ -242,8 +289,7 @@ main() { cmd_pick "$@" ;; rename) - echo "tmux-util: subcommand '$sub' is not implemented yet" >&2 - return 2 + cmd_rename "$@" ;; *) echo "tmux-util: unknown subcommand: $sub" >&2 -- cgit v1.2.3