Skip to content

Instantly share code, notes, and snippets.

@lance
Last active December 28, 2015 10:29
Show Gist options
  • Save lance/7486428 to your computer and use it in GitHub Desktop.
Save lance/7486428 to your computer and use it in GitHub Desktop.
Bootstrap a project with tmux
#!/bin/sh
if [ -z "$1" ] ; then
echo "usage: $0 <projectname> [/path/to/project]"
exit 1
fi
MYPROJECT=$1
# Setup some variables needed for bootstrapping the environment
if [ -z "$2" ] ; then
ROOT=${HOME}/src/${MYPROJECT}
else
ROOT=$2
fi
echo ${ROOT}
# Bootstrap a new session called ${MYPROJECT}
tmux new-session -d -s ${MYPROJECT}
# Rename the first window (using the session-name:id notation)
tmux rename-window -t ${MYPROJECT}:0 "cli"
# Create and label other windows
tmux new-window -t ${MYPROJECT}:1 -n "vim"
tmux new-window -t ${MYPROJECT}:2 -n "git"
# Send commands to the windows, use "C-m" to emulate "enter"
# On window 0, move to the directory with the source code
tmux send-keys -t ${MYPROJECT}:0 "cd ${ROOT}" C-m
# On window 1 split the pane vertically
tmux split-window -h -t ${MYPROJECT}:1
# Move to the directory with the source code and start Vim
tmux send-keys -t ${MYPROJECT}:1.1 "cd ${ROOT}" C-m
tmux send-keys -t ${MYPROJECT}:1.0 "cd ${ROOT}" C-m
tmux send-keys -t ${MYPROJECT}:1.0 "vim" C-m
tmux send-keys -t ${MYPROJECT}:1.0 ",n"
# Keep a shell to interact with Git
tmux send-keys -t ${MYPROJECT}:2 "cd ${ROOT}" C-m
tmux send-keys -t ${MYPROJECT}:2 "git status" C-m
# Switch to window 1
tmux select-window -t ${MYPROJECT}:1
# Force tmux to assume the terminal supports 256 colors and attach to the
# target session "${MYPROJECT}"
tmux -2 attach-session -t ${MYPROJECT}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment