Skip to content

Instantly share code, notes, and snippets.

@revenkroz
Last active December 3, 2020 17:11
Show Gist options
  • Save revenkroz/92a0b30d159edc447fbe52373024d92e to your computer and use it in GitHub Desktop.
Save revenkroz/92a0b30d159edc447fbe52373024d92e to your computer and use it in GitHub Desktop.
Control shared tmux session
if [[ $# < 1 ]] ; then
echo 'Usage: ./run-tmux.sh <start|stop|"command">'
exit 1
fi
SESSION_FILE=tmux.session
SESSION_NAME=shared
COMMAND=$1
if [[ $COMMAND = 'quit' ]] || [[ $COMMAND = 'exit' ]] || [[ $COMMAND = 'stop' ]]; then
tmux -S $SESSION_FILE kill-session -t $SESSION_NAME
exit 0
fi
if [[ $COMMAND = 'start' ]] || [[ $COMMAND = 'run' ]]; then
tmux -S $SESSION_FILE new -s $SESSION_NAME -d
exit 0
fi
if [[ $COMMAND = 'attach' ]]; then
tmux -S $SESSION_FILE attach -t $SESSION_NAME
exit 0
fi
tmux -S $SESSION_FILE send -t $SESSION_NAME.0 "$COMMAND" ENTER
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment