Skip to content

Instantly share code, notes, and snippets.

@yuki777
Last active December 15, 2022 02:10
Show Gist options
  • Save yuki777/7ff436993a997af2ec258e17273eaa98 to your computer and use it in GitHub Desktop.
Save yuki777/7ff436993a997af2ec258e17273eaa98 to your computer and use it in GitHub Desktop.
Reconnect tmux session script
#!/usr/bin/env bash
# https://gist.github.com/yuki777/7ff436993a997af2ec258e17273eaa98
# mkdir -p ~/bin; cd ~/bin
# wget -O tmuxx https://gist.githubusercontent.com/yuki777/7ff436993a997af2ec258e17273eaa98/raw/a8b459d95c32d9e2697608a1a701bdb04ac69232/tmuxx
# chmod 744 tmuxx
print_help(){
echo ' e.g. : tmuxx'
echo ' if "default" session exists, reconnect "default" session.'
echo ' if NOT exists, make "default" session.'
echo ' e.g. : tmuxx hoge '
echo ' if "hoge" session exists, reconnect "hoge" session.'
echo ' if NOT exists, make "hoge" session.'
exit
}
run_tmux(){
if [ `tmux ls 2>/dev/null |grep "$1: "|wc -l` -eq 1 ];then
tmux -u a -dt $1
else
tmux -u new -s $1
fi
}
if [ "$1" = "--help" ];then
print_help
elif [ "$1" = "" ];then
run_tmux "default"
else
run_tmux "$1"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment