Skip to content

Instantly share code, notes, and snippets.

@guemidiborhane
Created February 5, 2016 23:28
Show Gist options
  • Save guemidiborhane/8d4844695417a0b3c1b0 to your computer and use it in GitHub Desktop.
Save guemidiborhane/8d4844695417a0b3c1b0 to your computer and use it in GitHub Desktop.
This is my setup for working on rails projects in vi and tmux. Thanks to http://www.tofu.org/drupal/node/183 for inspiration. If it isn't a rails project, just open the directory with default tmux stuff.
#!/bin/bash
#
# Usage: tmuxme
# creates a tmux session with the name of the current directory
# if the current directory is a rails project, sets up 3 windows:
# server, console, and vim.
#
SESSION=$(basename $(pwd))
tmux has-session -t $SESSION >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Session $SESSION already exists. Attaching."
sleep 1
tmux attach -t $SESSION
exit 0;
fi
tmux new-session -d -s $SESSION
grep 'rails' 'Gemfile' >/dev/null 2>&1
if [ $? -eq 0 ]; then
tmux set-window-option -t $SESSION -g automatic-rename off
tmux new-window -dk -t $SESSION:1 -n 'server'
tmux new-window -dk -t $SESSION:2 -n 'console'
tmux new-window -dk -t $SESSION:3 -n 'vim'
tmux send -t $SESSION:1 'bundle exec rails server' ENTER
tmux send -t $SESSION:2 'bundle exec rails console' ENTER
tmux send -t $SESSION:3 'vi .' ENTER
tmux select-window -t $SESSION:3
fi
tmux attach -t $SESSION
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment