DarthSim / overmind

Process manager for Procfile-based applications and tmux
MIT License
2.78k stars 79 forks source link

On `connect`, create a new tmux session and move the relevant window in #155

Open canadaduane opened 1 year ago

canadaduane commented 1 year ago

(For context--My team is new to tmux. Overmind has been a fantastic process management solution in conjunction with turborepo for us).

Use case:

We'd like to be able to open multiple tabs in Terminal, and run overmind connect [service] once per tab, with a different service per tab. However, currently, when connecting to more than one service in this way, tmux treats it as the same session and essentially makes ALL tabs view the same window (tmux has a concept of one current/active window per session).

Is there a way to disable this behavior, or create a new session per overmind connect [service] call, and move the tmux window for that service into that session?

canadaduane commented 1 year ago

Ok, here's a solution:

I added the following to overmind.tmux.conf (the tmux config that we load via the -F switch, e.g. overmind start -F scripts/overmind.tmux.conf):

set-hook -g client-attached "run 'sess=\`tmux new -d -P -t \"#{session_name}\"\` && tmux switch-cli -t \"\${sess}#{window_index}\"'"

Whenever a new client attaches, this creates a new session within the same overmind session-group (a session-group shares all windows within all sessions), and switches to the same window_index as was current before creating the new session.

This is allows us to open a different "current window" in each new Terminal tab.