Skip to content

Instantly share code, notes, and snippets.

@kmtu
Last active May 22, 2017 09:31
Show Gist options
  • Save kmtu/32970a30843a57f8bc3cf16c621cfaca to your computer and use it in GitHub Desktop.
Save kmtu/32970a30843a57f8bc3cf16c621cfaca to your computer and use it in GitHub Desktop.
A bash script simplifying the procedure of sharing tmux session between users
#!/bin/bash
cmds=('new' 'join' 'list')
socket="/tmp/tmux-share"
grp="ggparty"
bin=tmux-share
usage0="tmux-share ${cmds[0]} <name>"
usage1="tmux-share ${cmds[1]} [<name>]"
usage2="tmux-share ${cmds[2]}"
usage="Usage:\n$usage0\n$usage1\n$usage2"
if [[ $# == 0 ]]; then
echo -e $usage
exit 1
fi
cmd=$1
name=$2
tmx="tmux -S $socket"
if [[ "$cmd" == ${cmds[0]} ]]; then
# new
if [[ $# < 2 ]]; then
echo -e "Usage: $usage0"
exit 1
fi
$tmx new -s $name -d
chgrp $grp $socket
elif [[ "$cmd" == ${cmds[1]} ]]; then
if [[ $name != '' ]]; then
$tmx attach -t $name
else
$tmx attach
fi
elif [[ "$cmd" == ${cmds[2]} ]]; then
$tmx list-session
else
echo -e $usage
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment