gbwczw
Last Updated: February 25, 2016
·
950
· kjellski
Gavatar big

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

Say Thanks
Respond

3 Responses
Add your response

12225
D3b2094f1b3386e660bb737e797f5dcc

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 ·
12232
Gavatar big

@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 ·
12245
D3b2094f1b3386e660bb737e797f5dcc

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

over 1 year ago ·
Filed Under