Skip to content

Instantly share code, notes, and snippets.

@FunTimeCoding
Last active August 29, 2015 14:02
Show Gist options
  • Save FunTimeCoding/70f32d6d37aac23f0ca1 to your computer and use it in GitHub Desktop.
Save FunTimeCoding/70f32d6d37aac23f0ca1 to your computer and use it in GitHub Desktop.
Simplify start and attach to tmux sessions.
#!/bin/bash
[ "${TMUX}" = "" ] || exit 0
has_session () {
tmux has-session -t $1 2>/dev/null
}
DEFAULT_NAME="_default"
if ! has_session "${DEFAULT_NAME}"; then
tmux new-session -s "${DEFAULT_NAME}" -d
fi
PS3="Select session: "
OPTIONS=($(tmux list-sessions -F "#S") "NEW")
select OPTION in "${OPTIONS[@]}"
do
case ${OPTION} in
"NEW")
read -p "Enter new session name: " SESSION_NAME
tmux new-session -s "${SESSION_NAME}"
break
;;
*)
tmux attach-session -t "${OPTION}"
break
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment