#!/bin/sh
# put this on .tmux.conf
# set-window-option -g automatic-rename off
# set-option -g allow-rename off
# Save the session in vim:
# :mks! $css
# Close Tmux session:
# tmux kill-session
# Put this in your .bashrc or .zshrc file, Uncomment the lines with export
# Path of Projects Folder ;b
#export PROJECTS_FOLDER=~/Projects/Rails/
# the Sessions script folder
#export SESSIONS_FOLDER=~/Scripts/sessions/
open_project(){
cd $PROJECTS_FOLDER${SESSION_NAME}/
# Path of vim session file
export css=${SESSIONS_FOLDER}${SESSION_NAME}.vim
# if the session is already opened
tmux has-session -t ${SESSION_NAME} &>/dev/null
if [ $? != 0 ] # If not, do
then
# A Terminal on :1
tmux new-session -s ${SESSION_NAME} -n Terminal -d
# A Vim, that make a session on openning and autoload that
tmux new-window -n Vim -t ${SESSION_NAME} 'vim -c "if file_readable(\"$css\")|source $css|else|mks $css|source $css|endif"'
# A Rails server
tmux new-window -n Server -t ${SESSION_NAME} 'rails s'
# A Rails console
tmux new-window -n Console -t ${SESSION_NAME} 'rails c'
# Back to Terminal
tmux select-window -t ${SESSION_NAME}:1
fi
# Load tmux session
tmux attach -t ${SESSION_NAME}
}
ALL_PROJECTS=($(ls ${PROJECTS_FOLDER}))
for i in "${ALL_PROJECTS[@]}"
do
echo $i
if [ "$i" == "$1" ] ; then
SESSION_NAME=$1
open_project
fi
done