fix(tmux): respect pane-base-index in setup_tmux_session#259
fix(tmux): respect pane-base-index in setup_tmux_session#259edlsh wants to merge 1 commit intofrankbria:mainfrom
Conversation
When a user's ~/.tmux.conf sets `setw -g pane-base-index 1` (common in
popular dotfiles and Oh My Zsh setups), tmux panes are numbered starting
at 1, not 0. Ralph previously handled `base-index` (windows) but
hardcoded pane targets as .0/.1/.2. With pane-base-index=1:
- send-keys -t session:0.0 targets a non-existent pane (silently fails)
- The Ralph loop never starts in the left pane
- The live-log tail and ralph-monitor land in the wrong panes
Visible symptom: running `ralph --monitor` opens a tmux session with
two empty shell prompts and a stray `tail -f` in a third pane. The
loop never runs.
Fix: add `get_tmux_pane_base_index` mirroring `get_tmux_base_index`,
then compute pane indices as `base_pane + {0,1,2}` throughout
`setup_tmux_session`. Default behavior (pane-base-index=0) is
unchanged.
Tests (test_tmux_integration.bats):
- Updated inline mirror of setup_tmux_session to match
- Parameterised the tmux show-options mock to return per-option values
via MOCK_TMUX_BASE_INDEX / MOCK_TMUX_PANE_BASE_INDEX
- Added 3 regression tests:
* pane-base-index 1 targets panes .1/.2/.3 (no .0 touches)
* base-index 1 + pane-base-index 1 targets 1.1/1.2/1.3
* get_tmux_pane_base_index defaults to 0
All 680 tests pass.
WalkthroughThis PR updates tmux pane targeting to respect the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
ralph_loop.sh (1)
293-302: Pane target derivation looks correct.Computing
pane0/pane1/pane2frombase_pane + {0,1,2}is the right fix for thepane-base-index=1case, and preserves existing behavior when it's 0.Optional nit:
local pane0=$((base_pane + 0))— the+ 0is a no-op;local pane0=$base_panewould be equivalent. The current form does keep visual symmetry with pane1/pane2, so feel free to leave as-is.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ralph_loop.sh` around lines 293 - 302, Replace the no-op arithmetic for pane0 with a simple assignment to avoid unnecessary expansion: change the declaration local pane0=$((base_pane + 0)) to local pane0=$base_pane while keeping pane1 and pane2 as local pane1=$((base_pane + 1)) and local pane2=$((base_pane + 2)); this touches the pane target derivation that uses get_tmux_pane_base_index and preserves behavior for pane0/pane1/pane2.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@ralph_loop.sh`:
- Around line 293-302: Replace the no-op arithmetic for pane0 with a simple
assignment to avoid unnecessary expansion: change the declaration local
pane0=$((base_pane + 0)) to local pane0=$base_pane while keeping pane1 and pane2
as local pane1=$((base_pane + 1)) and local pane2=$((base_pane + 2)); this
touches the pane target derivation that uses get_tmux_pane_base_index and
preserves behavior for pane0/pane1/pane2.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 2346a55a-57f4-4777-ab70-95533e2f4981
📒 Files selected for processing (2)
ralph_loop.shtests/integration/test_tmux_integration.bats
Summary
Ralph's
--monitormode silently fails to start the loop when the user's~/.tmux.confsetssetw -g pane-base-index 1. The tmux session opens with two empty shell prompts and a straytail -fin a third pane — the Ralph loop itself never runs.Root cause:
setup_tmux_sessionhandlesbase-index(for windows) viaget_tmux_base_indexbut hardcodes pane targets as.0,.1,.2. Withpane-base-index 1, tmux numbers panes from 1 so:send-keys -t session:0.0 "$ralph_cmd"targets a non-existent pane and silently drops the input → the Ralph loop never startssend-keys -t session:0.1 "tail -f live.log"lands in the actual left-most pane (which was supposed to be the loop)send-keys -t session:0.2 "ralph-monitor"targets a pane that may or may not exist depending on split orderThis is common because many popular dotfiles / Oh My Zsh setups ship with
setw -g pane-base-index 1enabled.Repro
Fix
Add
get_tmux_pane_base_indexmirroringget_tmux_base_index, then compute pane indices asbase_pane + {0,1,2}throughoutsetup_tmux_session. Default behavior (pane-base-index 0) is unchanged.Tests
setup_tmux_sessionintest_tmux_integration.bats(per the file's "keep in sync" convention)tmux show-optionsmock to return per-option values viaMOCK_TMUX_BASE_INDEX/MOCK_TMUX_PANE_BASE_INDEX— previously it always returned0setup_tmux_session respects pane-base-index 1 for all pane targets— verifies.1/.2/.3are used and.0is never touchedsetup_tmux_session respects both base-index and pane-base-index set to 1— double non-zero caseget_tmux_pane_base_index returns 0 as default— mirrors existingget_tmux_base_indexdefault testAll 680 tests pass (16 original tmux + 3 new + 1 renumbered concurrent test, plus the rest of the suite).
Checklist
.tmux.confsnippetpane-base-index 0(all 16 original tmux tests pass unchanged)npm test) passes — 680/680bash -n ralph_loop.sh) passesSummary by CodeRabbit
Release Notes
Bug Fixes
Tests