Last active
May 8, 2024 09:00
-
-
Save codequokka/f058216231d0d251536e367719f67296 to your computer and use it in GitHub Desktop.
Start tmux automatically on zsh
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
# Start the tmux session if not alraedy in the tmux session | |
if [[ ! -n $TMUX ]]; then | |
# Get the session IDs | |
session_ids="$(tmux list-sessions)" | |
# Create new session if no sessions exist | |
if [[ -z "$session_ids" ]]; then | |
tmux new-session | |
fi | |
# Select from following choices | |
# - Attach existing session | |
# - Create new session | |
# - Start without tmux | |
create_new_session="Create new session" | |
start_without_tmux="Start without tmux" | |
choices="$session_ids\n${create_new_session}:\n${start_without_tmux}:" | |
choice="$(echo $choices | fzf | cut -d: -f1)" | |
if expr "$choice" : "[0-9]*$" >&/dev/null; then | |
# Attach existing session | |
tmux attach-session -t "$choice" | |
elif [[ "$choice" = "${create_new_session}" ]]; then | |
# Create new session | |
tmux new-session | |
elif [[ "$choice" = "${start_without_tmux}" ]]; then | |
# Start without tmux | |
: | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment