-mumdg
Last Updated: December 28, 2016
·
4.255K
· zan5hin
Edba87917427518542fb7db298a8904b

Automatically reattach tmux session using iTerm2

Using the "Send text at start" option in iTerm2, it is possible to automatically re-attach to an existing tmux session.

Open iTerm2's preferences, then select the 'Profiles' tab, and finally the 'General' pane. In the 'Command' section locate the 'Send text at start:' option and put in this command, substituting your session name for base.

tmux attach -t base || tmux new -s base

Now anytime you start iTerm2 (or create a new window) tmux will first try to attach to a session called base, or, if that session doesn't exist, it will create a new session called base.

As long as you typically use just one session (with multiple windows and panes), this tip will allow you to quit iTerm2 and not lose your tmux session.

Say Thanks
Respond

2 Responses
Add your response

7013
8adeda7e26cbda75581c0fc9955251b7

Cool, nice share!

over 1 year ago ·
18905
5e47e75af9d584936f6b4be3520c75d7

Just in time tip. I was setting up my iTerm2 to work with tmux.
As I use tmuxinator, I replaced the second part:

tmux attach -t default || mux start default

Thanks for the great tip anyway. My OSX setup feels nicer.

over 1 year ago ·