Skip to content

Instantly share code, notes, and snippets.

@febrianrendak
Created March 21, 2017 04:21
Show Gist options
  • Save febrianrendak/3a297dbe53febff8dccece2bb71bc89f to your computer and use it in GitHub Desktop.
Save febrianrendak/3a297dbe53febff8dccece2bb71bc89f to your computer and use it in GitHub Desktop.

Revisions

  1. febrianrendak created this gist Mar 21, 2017.
    42 changes: 42 additions & 0 deletions tmux-webdev.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    #!/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."