Skip to content

Instantly share code, notes, and snippets.

@yumike
Created August 5, 2012 21:06
Show Gist options
  • Save yumike/3267127 to your computer and use it in GitHub Desktop.
Save yumike/3267127 to your computer and use it in GitHub Desktop.
start tmux session for project
#!/bin/sh
if [ ! $1 ]; then
echo "Error: project name is not specified."
exit 1
fi
PROJECT_NAME="$1"
SESSION_NAME=${PROJECT_NAME//\./-}
PROJECT_PATH="$PROJECT_HOME/$PROJECT_NAME"
VIRTUALENV_PATH="$WORKON_HOME/$PROJECT_NAME"
if [ ! -d "$PROJECT_PATH" ]; then
echo "Error: directory $PROJECT_PATH does not exist."
exit 1
fi
if [ ! -d "$VIRTUALENV_PATH" ]; then
echo "Error: directory $VIRTUALENV_PATH does not exist."
exit 1
fi
tmux has-session -t $SESSION_NAME &> /dev/null
if [ $? != 0 ]; then
echo "Session for project $PROJECT_NAME does not exist. Starting."
unset TMUX
tmux new-session -s $SESSION_NAME -d
tmux send-keys -t $SESSION_NAME "workon $PROJECT_NAME && clear" C-m
tmux split-window -h -t $SESSION_NAME
tmux send-keys -t $SESSION_NAME:0.1 "cd $PROJECT_PATH && clear && vim" C-m
tmux select-pane -t $SESSION_NAME:0.0
tmux split-window -v -t $SESSION_NAME
tmux send-keys -t $SESSION_NAME:0.1 "workon $PROJECT_NAME && clear" C-m
tmux select-pane -t $SESSION_NAME:0.2
fi
if [ "$TERM" == "xterm-256color" ]; then
tmux attach -t $SESSION_NAME
else
tmux switch -t $SESSION_NAME
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment