Created
September 11, 2022 18:55
-
-
Save jcanfield/e1057e4fa93e6d8b9953346b7fa3d114 to your computer and use it in GitHub Desktop.
Simple Bash Script to Create a New Session
This file contains hidden or 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
#!/bin/bash | |
# USAGE: ./tmux-new.sh SESSION_NAME | |
# | |
# Credit to Keon Woortman | |
# URL: https://koenwoortman.com/tmux-sessions-should-be-nested-with-care-unset-tmux-to-force/ | |
session_name="$1" | |
# 1. First you check if a tmux session exists with a given name. | |
tmux has-session -t=$session_name 2> /dev/null | |
# 2. Create the session if it doesn't exists. | |
if [[ $? -ne 0 ]]; then | |
TMUX='' tmux new-session -d -s "$session_name" | |
fi | |
# 3. Attach if outside of tmux, switch if you're in tmux. | |
if [[ -z "$TMUX" ]]; then | |
tmux attach -t "$session_name" | |
else | |
tmux switch-client -t "$session_name" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment