Skip to content

feat: add --tmux-socket flag and TmuxClient socket routing - #360

Open
kalbasit wants to merge 5 commits into
ck3mp3r:mainfrom
kalbasit:feat/laio-plugin
Open

feat: add --tmux-socket flag and TmuxClient socket routing#360
kalbasit wants to merge 5 commits into
ck3mp3r:mainfrom
kalbasit:feat/laio-plugin

Conversation

@kalbasit

@kalbasit kalbasit commented May 18, 2026

Copy link
Copy Markdown

Problem

When laio is used as a tmux plugin — where tmux runs on a non-default socket — every laio command was silently targeting the default tmux server. This caused laio to operate on the wrong server or fail outright.

Solution

Add a global --tmux-socket <path> flag (and LAIO_TMUX_SOCKET env var fallback) that pins all tmux operations to the specified server. The flag lives on the top-level CLI struct so it applies consistently to every subcommand without needing to be threaded through each one manually.

  • TmuxClient stores the socket and prepends -S <path> to every tmux invocation
  • start, stop, list, config list, session list, and session yaml all honor the resolved socket
  • The M-l picker popup binding embeds --tmux-socket in the reopened laio start --show-picker command so the picker re-opens against the same server
  • Passing --tmux-socket with Zellij emits a warning and is ignored (flag is tmux-specific)

Test plan

  • cargo test --quiet passes
  • laio --tmux-socket /tmp/my.sock start <session> targets the correct server (tmux -S /tmp/my.sock ls confirms)
  • LAIO_TMUX_SOCKET=/tmp/my.sock laio start <session> works identically
  • --tmux-socket takes priority over LAIO_TMUX_SOCKET
  • Pressing M-l inside a session started with --tmux-socket reopens the picker on the same server

@kalbasit

kalbasit commented May 18, 2026

Copy link
Copy Markdown
Author

This change is part of the following stack:

Change managed by git-spice.

@kalbasit
kalbasit force-pushed the feat/laio-plugin branch 3 times, most recently from 34d1d97 to d37708f Compare May 18, 2026 19:14
@kalbasit kalbasit changed the title feat: add --tmux-socket and in-session configure mode feat: add --tmux-socket flag and TmuxClient socket routing May 18, 2026
Add --tmux-socket <path> to `laio start` (with LAIO_TMUX_SOCKET env
var as fallback) so laio can target a specific tmux server socket
rather than the default one. When set, -S <path> is prepended to
every tmux command so all operations hit the intended server.

The flag is named --tmux-socket (not --socket) to make its scope
explicit: it is tmux-specific and has no meaning for Zellij. A
warning is emitted when --tmux-socket is passed with Zellij. The
socket field on TmuxClient is private and exposed only via has_socket()
to keep the detail encapsulated within the client.

Also refactors process_windows() into process_windows_for() to accept
an explicit session name and force_new_windows flag, preparing for
in-session mode in the next commit.

Tests cover flag parsing, LAIO_TMUX_SOCKET env fallback, and -S
prepended to tmux commands.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@kalbasit
kalbasit force-pushed the feat/laio-plugin branch from d37708f to 92a50f7 Compare May 18, 2026 19:28
@kalbasit
kalbasit marked this pull request as draft May 18, 2026 19:38
@kalbasit
kalbasit marked this pull request as ready for review May 19, 2026 00:48
@kalbasit

kalbasit commented May 20, 2026

Copy link
Copy Markdown
Author

@ck3mp3r Thanks for Laio!

My project swm makes use of laio, and this PR (and another upcoming PR) are required to make it work. Do you mind giving this a review?

Comment thread src/app/cli/command_line.rs Outdated
Comment thread src/muxer/tmux/client.rs Outdated
kalbasit added 2 commits May 20, 2026 07:49
Inline test modules in source files conflict with the project
convention of using separate _test.rs files. Move the Cli socket
tests to src/app/cli/command_line_test.rs (declared from mod.rs)
and widen resolved_socket() to pub(crate) so the sibling test
module can access it.
Introducing a socket path broke the existing cmd_basic!("tmux", ...)
pattern because the socket prefix had to be injected per-call. The
temporary fix used explicit Type::Basic blocks everywhere. Add a
tmux_cmd!(socket, args=[...]) macro that incorporates the socket
prefix, then use it for all static-arg call sites; the two dynamic-
arg sites (create_session env args and register_command send-keys)
retain the tmux_cmd() helper method.
@kalbasit
kalbasit requested a review from ck3mp3r May 20, 2026 15:55
@ck3mp3r

ck3mp3r commented May 21, 2026

Copy link
Copy Markdown
Owner

@kalbasit I think this use case is very specific to your workflow and changing the cli api and just adding socket support for tmux and not zellij does not feel like sound architecture. Also the implementation feels like a bolt on to be honest. I would have liked a more generic approach. Have you tried using an environment variable inside your cli to control where tmux has the socket for sessions wrapped by your cli?

@kalbasit

Copy link
Copy Markdown
Author

@kalbasit I think this use case is very specific to your workflow and changing the cli api and just adding socket support for tmux and not zellij does not feel like sound architecture. Also the implementation feels like a bolt on to be honest. I would have liked a more generic approach. Have you tried using an environment variable inside your cli to control where tmux has the socket for sessions wrapped by your cli?

Thanks — the bolt-on critique is fair, and I think there's a cleaner path that doesn't add any CLI surface at all.

$TMUX already carries the socket path (socket,pid,session), and laio reads it via is_inside_session(). Parsing the socket out and prepending -S <socket> to tmux commands whenever $TMUX is set would replace --tmux-socket entirely — no flag, no env var, and no change to anyone's existing usage:

  • User on the default socket: extracted path matches what plain tmux would resolve to → behaviour unchanged.
  • User outside tmux: $TMUX unset → behaviour unchanged.
  • User on a custom socket (tmux -L name / tmux -S /path): laio currently issues commands on the default socket while the user is on a different one, and switch-client can't find the session it just created. Reading from $TMUX fixes that — bug fix, not a behaviour change.

For zellij, the same pattern would apply with $ZELLIJ if/when it makes sense — separate PR.

Would dropping --tmux-socket / LAIO_TMUX_SOCKET entirely in favour of $TMUX-derived routing match what you had in mind? Happy to rework.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants