Safely exec tmux upon login

Viewed 577

I would like to execute tmux upon logging into a shell for my user. I am using fish, but I think this question is relevant to any shell. So far, I've accomplished this by following the advice in this question: https://askubuntu.com/questions/560253/automatically-running-tmux-in-fish, specifically, adding the following line to my config.fish:

test $TERM != "screen"; and exec tmux

However, I have one major issue with this approach, and that is if tmux fails to start, perhaps if I've introduced a syntax error in my .tmux.conf file, the shell process immediately exits, booting me out of the session.

Is there a way to automatically run tmux in new shell executions whereby I can:

  • Catch errors and fallback on a "plain" shell execution (i.e. just fish without tmux)
  • Not have to exit a login twice - once to quit tmux then again to quit fish

?

2 Answers
Related