Skip to content

Instantly share code, notes, and snippets.

@fsgreco
Last active December 28, 2021 13:19
Show Gist options
  • Save fsgreco/9458eb18138ca2e6e3c673799b4a2613 to your computer and use it in GitHub Desktop.
Save fsgreco/9458eb18138ca2e6e3c673799b4a2613 to your computer and use it in GitHub Desktop.
[zsh function] manage tmux sessions
function tm() (
[ -z "$1" ] && echo 'Please give me the name of the session' && exit 1
# If there is no tmux server running create the session
[[ -z "$TMUX" && ! $(tmux ls 2> /dev/null) ]] && tmux new -s $1 && exit 0
# There is at least a tmux server running
# If you're not inside tmux either attach to the session or create it:
[ -z "$TMUX" ] && tmux new -A -s $1 && exit 0
# You're already inside tmux => [ -n "$TMUX" ] should be true
# If session doesn't exist create it and then switch to it
if ! tmux has -t $1 > /dev/null 2>&1; then
tmux new -d -s $1
fi
tmux switchc -t $1
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment