Starting Your Terminal with tmux
22nd April 2023 - Saturday
I am getting more comfortable with tmux
and I want to make sure I don't forget to use it when I'm at the command prompt. So, I made a simple Bash script to automatically connect to an existing session or start a new session when I start my terminal:
tmux-start.sh
:
#!/bin/bash
tmux ls > /dev/null ; [ $? == 0 ] && tmux attach || tmux
tmux ls
will list existing sessions, but I'm dumping that output and just using its return value which will be0
if there are any existing sessions.$?
is the return value of the previous command&&
...||
is basically equivalent to a ternary operator in other programming languages