Last Updated: December 26, 2018
·
1.443K
· kjellski

tmux always reattach

Really small tip here:

I've switched to tmux recently and was always wondering why the default behaviour was to always create a new session. I've understood that it's usable but it was hindering my workflow coming from screen. Whatever... I came up with a small alias which works very well for me:

alias tmux='tmux attach || tmux'

This alias always reattaches me to any existing session, but if none exists yet, creates a new one. Always the right behaviour for me, does it fit your needs too?

Cheers,
@kjellski

3 Responses
Add your response

Cool tip!

FYI - the book From Bash to Z Shell: Conquering the Command Line (which I enjoyed) recommends alias names that do not clobber existing names, like alias ll='ls -l' instead of alias ls='ls -l'. This avoids unexpected behavior in scripts that call the command and for anyone else using your terminal (which is kind of the point for tmux, right?). Just some food for thought.

over 1 year ago ·

@steve-jansen thanks for the hint, you are right! I tend to unalias* in scripts, just to make sure. For me that is the rare case and in all day circumstances I like my aliases to be convenient.

over 1 year ago ·

@kjellski - learned something new today. I'm going to start including unalias -a in my scripts. Thanks!

over 1 year ago ·