Skip to content

Instantly share code, notes, and snippets.

@eric-wood
Created October 2, 2014 06:59
Show Gist options
  • Save eric-wood/ad80c6dfd70f008ebda1 to your computer and use it in GitHub Desktop.
Save eric-wood/ad80c6dfd70f008ebda1 to your computer and use it in GitHub Desktop.
Auto-attach for screen/tmux on login!

Keeping a tmux/screen session going, the easy way

Hey so what if you wanted tmux or screen to pop open your session every time you log in, and then automatically log you out when you detach?!

That'd be pretty convenient.

Here add this to your ~/.bash_profile:

[[ $TERM != "screen" ]] && tmux att && exit

Feel free to substitute tmux att with screen -r if you're in that camp. I don't judge.

Cool.

Now go ahead and detach, log out, then log back in.

MAGIC I TELL YOU. MAGIC.

Thanks.

http://tilde.club/~eric/

@pushcx
Copy link

pushcx commented Oct 2, 2014

I think this might be a better check:

[ -z $TMUX ] && tmux att && exit

I don't know the equivalent for screen. (Also, when you are tinkering with ~/.bash_profile (especially with an 'exit', you should log in from a new terminal before you close your editor. If you goof you might lock yourself out.)

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