Last active
December 28, 2021 13:19
-
-
Save fsgreco/9458eb18138ca2e6e3c673799b4a2613 to your computer and use it in GitHub Desktop.
[zsh function] manage tmux sessions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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