Created
December 15, 2022 02:11
-
-
Save yuki777/da803fb23bc814d0bdb60048c374d1ed to your computer and use it in GitHub Desktop.
Attach tmux session script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# https://gist.github.com/yuki777/da803fb23bc814d0bdb60048c374d1ed | |
# mkdir -p ~/bin; cd ~/bin | |
# wget -O tmuxxx https://gist.githubusercontent.com/yuki777/da803fb23bc814d0bdb60048c374d1ed/raw/d6eaff33bb5c5a900bb98799dba793678e78bb38/tmuxxx | |
# chmod 744 tmuxx | |
print_help(){ | |
echo ' e.g. : tmuxxx' | |
echo ' if "default" session exists, attach "default" session.' | |
echo ' if NOT exists, make "default" session.' | |
echo ' e.g. : tmuxx hoge' | |
echo ' if "hoge" session exists, attach "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 attach -t $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