Tmux-like Wezterm Multiplexing Sessions #1322
Replies: 3 comments 19 replies
-
Thanks for putting this together! I'm going to digest this a bit. I'd love to hear what thoughts you have on making this sort of functionality a first-class thing in wezterm; especially the parts that were awkward or that don't work quite how you'd like them to in your mux script! |
Beta Was this translation helpful? Give feedback.
-
Let's have the "tmux -CC " please, then all are resolved. |
Beta Was this translation helpful? Give feedback.
-
Would it be possible to setup workspaces to be tied to a single window (and not hide other windows) in a similar manner to how it is done in tmux sessions. I tried using workspaces, but they can be annoying when using a tiling window manager. If I have a wezterm window open on another desktop it will also be hidden when I switch workspace., and when I reopen the workspace all the windows become a mess because of the tiling window manager. I really like using wezterm so far, and having sessions would be lovely |
Beta Was this translation helpful? Give feedback.
-
I worked on a little implementation of Tmux-like sessions for Wezterm via a quick and dirty shell script, and I'd love to show it off here for multiple reasons, but mainly because I think it could start some discussions and there was some interest in this already.
Please do chime in to tell me there's an easier way to implement this, if there is 😆 I've gone off of the existing docs and information from issues and discussion threads, but I haven't read the
wezterm
codebase extensively, so I'm just learning more about it by doing this.Mainly, I've seen that two prior discussions relate to this topic:
How my script works is pretty similar to a tmux-like workflow:
wezterm-mux-server
s must be spawnable as daemonswezterm-mux-server
instance diesTo just get to the point, here is the script in question: https://github.com/kitten/nix-system/blob/abe3322f8991fe54e681f091d7e3bd438fcb60df/config/scripts/wezmux.sh
How does it work?
This script "exploits" the existing
unix_domains
config. It does not integrate with Wezterm itself that well, and instead runswezterm
orwezterm-mux-server
manually. I'm on macOS, hence I haven't spent too much time on launching new Wezterm GUIs on other platforms, since on macOS I can simply callopen -a ... --args
, which isn't perfect but works for now.All sessions are kept in
.local/share/wezterm/sessions/*
. Each session has a folder that contains apid
file with the daemon's PID, and a logfile. Creating thesock
socket file is a responsibility ofwezterm-mux-server
itself. I don't let the server daemonize itself, but instead, the bash script itself becomes a small "faux daemon" and puts its own PID into thepid
file.Because of the folder structure, I can list out running sessions. Each time a new session is created, the bash script spawns a daemonized version of itself that traps exit signals to a small callback function that cleans up the session folder, and terminates the
wezterm-mux-server
as needed. Thewexterm-mux-server
is started with an overriden--config "unix_domains=..."
config entry, which points at this newsessions/*/
folder.The main script can then attach to the sessions by launching the GUI executable directly, on macOS via:
open -a $WEZTERM_EXECUTABLE -n --args ...
.What I've discovered is that this workflow is actually extremely comparable to tmux. I can launch a Wezterm window without a mux server (which I call default) and use it to create new sessions and attach to those. Once the session's Wezterm GUI window is spawned, I can exit the default (sessionless) window manually. The session stays active even when I close this new window and I can repeatedly attach to it.
How well does it integrate?
There's a bunch of things I do to my
wezterm.lua
configuration to make this a little easier to handle.I had to, for instance, create a small status_right modification that reads
unix_domains
to display the currently active session's name: https://github.com/kitten/nix-system/blob/abe3322f8991fe54e681f091d7e3bd438fcb60df/config/home/wezterm/init.lua#L5-L13Apart from that there's several things that I wish I could do:
So, I'm personally pretty happy with this admittedly super hacky solution 😄, but I think this could hopefully help form a better idea of what capabilities the GUI is lacking, in terms of its API and the GUI socket.
Beta Was this translation helpful? Give feedback.
All reactions