Created
March 21, 2017 04:21
-
-
Save febrianrendak/3a297dbe53febff8dccece2bb71bc89f to your computer and use it in GitHub Desktop.
tmux script to create new session from current directory
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
#!/bin/bash | |
function tmux_web { | |
SESSION_NAME=$1 | |
#echo "Create.." | |
tmux -L $SESSION_NAME new -s $SESSION_NAME -n editor -d | |
#echo "Creat first pane (editor).." | |
tmux -L $SESSION_NAME send-keys -t $SESSION_NAME 'vim' C-m | |
#echo "Run vim in first pane.." | |
tmux -L $SESSION_NAME new-window -n console -t $SESSION_NAME | |
#echo "Create second pane (console).." | |
tmux -L $SESSION_NAME split-window -h -t $SESSION_NAME:2 | |
#echo "Split second pane.." | |
tmux -L $SESSION_NAME new-window -n server -t $SESSION_NAME | |
#echo "Create third pane (server)" | |
tmux -L $SESSION_NAME new-window -n guard -t $SESSION_NAME | |
#echo "Create fourth pane (guard)" | |
tmux -L $SESSION_NAME new-window -n docker -t $SESSION_NAME | |
#echo "Create fith pane (docker)" | |
tmux -L $SESSION_NAME split-window -h -t $SESSION_NAME:5 | |
#echo "Split fifth pane (docker)" | |
tmux -L $SESSION_NAME attach -t $SESSION_NAME | |
#echo "Start tmux session $SESSION_NAME." | |
} | |
#base new session name is current directory | |
DIR_NAME=${PWD##*/} | |
echo "Trying to create new Tmux session with name '$DIR_NAME'." | |
tmux has-session -t $DIR_NAME 2>/dev/null | |
if [ $? -eq 1 ] | |
then | |
echo "Session not found. Create Session '$DIR_NAME'." | |
tmux_web $DIR_NAME | |
else | |
#random string as new session suffix | |
RAND_NUMB=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 2 | head -n 1) | |
echo "Session found. Create session with name '$DIR_NAME$RAND_NUMB'" | |
tmux_web "$DIR_NAME$RAND_NUMB" | |
fi | |
echo "Start tmux session $DIR_NAME." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment