Skip to content

Instantly share code, notes, and snippets.

@ewilazarus
Created May 31, 2015 19:44

Revisions

  1. Gabriel Lima created this gist May 31, 2015.
    61 changes: 61 additions & 0 deletions bootstrap_tmux_session.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,61 @@
    #!/usr/bin/env sh

    TARGET_DIR=~/Workspace
    PY_VERSION=python3

    while getopts d:p:v: opts; do
    case ${opts} in
    d) TARGET_DIR=${OPTARG} ;;
    p) PY_VERSION=${OPTARG} ;;
    v) VENV=${OPTARG} ;;
    esac
    done

    # Creates new session 'devenv' with a window called 'vim'
    tmux new-session -s devenv -n run -d
    tmux send-keys -R -t devenv:0 "cd ${TARGET_DIR}" C-m C-l
    if [ ! -z "$VENV" ]
    then
    tmux send-keys -R -t devenv:0 "workon ${VENV}" C-m C-l
    fi

    # Creates new window called 'vim'
    tmux new-window -t devenv -n vim

    # Makes the 'vim' window title fixed
    tmux set-window-option -tdevenv:1 -g allow-rename off

    # CD into the given directory
    tmux send-keys -R -t devenv:1 "cd ${TARGET_DIR}" C-m C-l
    if [ ! -z "$VENV" ]
    then
    tmux send-keys -R -t devenv:1 "workon ${VENV}" C-m C-l
    fi
    tmux send-keys -R -t devenv:1 'vim' C-m
    tmux send-keys -R -t devenv:1 C-n

    # Creates new window called 'shell/repl'
    tmux new-window -t devenv -n shell/repl

    # Makes the 'shell/repl' window title fixed
    tmux set-window-option -t devenv:2 -g allow-rename off

    # Splits the 'shell/repl' window vertically
    tmux split-window -t devenv:2 -h
    tmux send-keys -R -t devenv:2.0 "cd ${TARGET_DIR}" C-m C-l
    tmux send-keys -R -t devenv:2.0 'ls' C-m
    tmux send-keys -R -t devenv:2.1 "cd ${TARGET_DIR}" C-m C-l
    if [ ! -z "$VENV" ]
    then
    tmux send-keys -R -t devenv:2.1 "workon ${VENV}" C-m C-l
    fi
    tmux send-keys -R -t devenv:2.1 "${PY_VERSION}" C-m

    # Set focus to the pane 2.0 (shell)
    tmux select-pane -t devenv:2.0

    # Selects the 'vim' window
    tmux select-window -t devenv:1

    # Attaches to the session
    tmux attach -t devenv