Skip to content

Instantly share code, notes, and snippets.

@mikekwright
Last active December 23, 2015 21:00
Show Gist options
  • Select an option

  • Save mikekwright/ba5ab4de244463bc77fc to your computer and use it in GitHub Desktop.

Select an option

Save mikekwright/ba5ab4de244463bc77fc to your computer and use it in GitHub Desktop.
This is a sample of a tmux script that can be used to create an environment with a long running command on the left (like a test runner) and on the right vim opened
#!/usr/bin/env bash
# vim: ft=sh
SESSION_NAME=${SESSION_NAME-default}
COMMAND=${COMMAND-''}
show_usage() {
echo -e "Usage: $0 <directory>\n"
echo -e "\tOptions as environment variables"
echo -e "\t\tSESSION_NAME: name of tmux session (allows for reattach)"
echo -e "\t\tCOMMAND: command to run in command window (left pane)"
}
if [[ $# != 1 ]]; then
echo "Missing required argument"
show_usage
exit 1
else
DIRECTORY=$1
fi
if [ ! -d "$DIRECTORY" ]; then
echo "Directory does not exist"
show_usage
exit 2
fi
pushd $DIRECTORY >> /dev/null
# Create the session disconnected
# This gives us a single window with a single pane
tmux new-session -s "$SESSION_NAME" -n "$SESSION_NAME" -d
tmux send-keys $COMMAND C-m
# Create the second pane with it taking 80% of the screen
# this is the pane that will have vim running
tmux split-window -h -p 80
tmux send-keys vim C-m
# Below line can be uncommented if you want nerdtree to show on vim launch (uses Ctrl+e)
#tmux send-keys C-e
# Attach to Session
tmux attach-session -t "$SESSION_NAME"
popd >> /dev/null
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment