From b4cd792f847e9513fd4e9bac4ee26b492dbdadc3 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Tue, 19 May 2026 13:01:19 -0500 Subject: feat(tmux-util): add go subcommand (attach-or-create) tmux-util go attaches to a session named if it exists, creates it otherwise. Behavior depends on whether the caller is already inside tmux: - Outside tmux: `tmux attach-session -t ` (existing) or `tmux new-session -s -c $PWD` (new). - Inside tmux (TMUX env set): `tmux switch-client -t ` (existing) or `tmux new-session -d -s -c $PWD` followed by `switch-client` (new). Attaching from inside tmux would nest sessions and break the outer view, so the inside path uses switch-client instead. The existence check uses `tmux has-session -t =` with the leading `=` to force exact-match. Without it, tmux does prefix matching, which would let `go foo` resolve to a session named `foobar`. I added 6 new tests covering both inside/outside-tmux paths, both create/attach paths, plus error handling for missing or empty name arguments. fake-tmux picked up handlers for new-session (mutates state), attach-session and switch-client (record-only), and the `=`-prefix form of has-session. Total suite: 32 tests, all green. --- tests/tmux-util/fake-tmux | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests/tmux-util/fake-tmux') diff --git a/tests/tmux-util/fake-tmux b/tests/tmux-util/fake-tmux index ba2d5cc..163ea24 100755 --- a/tests/tmux-util/fake-tmux +++ b/tests/tmux-util/fake-tmux @@ -97,6 +97,8 @@ case "$cmd" in *) shift ;; esac done + # tmux accepts a `=name` form to force exact match; strip the prefix. + session="${session#=}" while IFS=' ' read -r name attached pids _rest; do if [ "$name" = "$session" ]; then exit 0 @@ -104,6 +106,25 @@ case "$cmd" in done < "$STATE" exit 1 ;; + new-session) + detached=0 + name="" + cwd="" + while [ "$#" -gt 0 ]; do + case "$1" in + -s) shift; name="$1"; shift ;; + -c) shift; cwd="$1"; shift ;; + -d) detached=1; shift ;; + *) shift ;; + esac + done + attached=1 + [ "$detached" -eq 1 ] && attached=0 + printf '%s %s - 0 1 %s\n' "$name" "$attached" "${cwd:-/tmp}" >> "$STATE" + ;; + attach-session|switch-client) + # No state mutation needed — the call log already records intent. + ;; kill-session) session="" while [ "$#" -gt 0 ]; do -- cgit v1.2.3