Skip to content

Instantly share code, notes, and snippets.

@madalinpopa
Created August 6, 2025 09:16
Show Gist options
  • Save madalinpopa/08877b439fc5a5122cdb224b512387c4 to your computer and use it in GitHub Desktop.
Save madalinpopa/08877b439fc5a5122cdb224b512387c4 to your computer and use it in GitHub Desktop.
Start the tmux session if not already in the tmux session
# Start the tmux session if not already in the tmux session
if [[ -z $TMUX ]]; then
mapfile -t sessions < <(tmux list-sessions -F "#S" 2>/dev/null)
choices=("${sessions[@]}" "Create new session" "Start without tmux")
choice=$(printf "%s\n" "${choices[@]}" | sk --margin 10% --color='bw')
if [[ " ${sessions[*]} " == *" $choice "* ]]; then
tmux attach-session -t "$choice"
elif [[ "$choice" == "Create new session" ]]; then
tmux new-session
fi
# Else do nothing (start without tmux)
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment