aboutsummaryrefslogtreecommitdiff
path: root/dotfiles
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-19 13:17:06 -0500
committerCraig Jennings <c@cjennings.net>2026-05-19 13:17:06 -0500
commitf91586248f467a2ba7a62f76caee1f40927655d9 (patch)
tree39ff6ae73fa53f8164c0a8ad104dc550313cad44 /dotfiles
parent95e1e0be4905ff5d37b52f889f5dda65543e2b51 (diff)
downloadarchsetup-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 'dotfiles')
-rwxr-xr-xdotfiles/common/.local/bin/tmux-util50
1 files changed, 48 insertions, 2 deletions
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
@@ -36,6 +36,53 @@ 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