Skip to content

Instantly share code, notes, and snippets.

@rwese
Created September 21, 2024 18:20
Show Gist options
  • Save rwese/10485c9a5e37acc1c7733f0cdd2e3a04 to your computer and use it in GitHub Desktop.
Save rwese/10485c9a5e37acc1c7733f0cdd2e3a04 to your computer and use it in GitHub Desktop.
wezterm - sticky tmux session, automatically reopen host specific session
-- this is a snippet to set the wezterm default_prog to start a hostname
-- specific session, to ensure different environments always run the same
-- session by default.
--
-- using tmux-resurrect is also possible, but for me this now works just fine
--
local wezterm = require("wezterm")
-- most reliable way to get the hostname i've found
local handle = io.popen("hostname -s")
local output = "no_hostname"
if handle ~= nil then
output = handle:read("*a")
end
-- command output might contain trailing whitespaces
local hostname = output:gsub("[\n\r]", " ")
local program_tmux = "/usr/bin/tmux"
-- ARG "-2" is needed to ensure graphical support
config.default_prog = {
"sh",
"-c",
program_tmux .. " -2 attach-session -t " .. hostname .. " || " .. program_tmux .. " -2 new -s " .. hostname .. "",
}
return config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment