I would like to automate a scenario when I am working on a rails project, and I think screen is the perfect way to accomplish this without having to drag and drop multiple windows after every startup (it makes me angry when I have to touch my mouse).

Idealy I will type:

$ ./bitchin_screen_automation project_name

and

There are a few tools that I always launch when working with rails (in this order) rails server, spork, autotest, and a printout of sql commands being executed to the database.

It usually ends up in a formation looking similar to: this

The following .screen rc generates something similar, but I cannot figure out how to automate the commands to start the rails server in each of the splits, nor pass any commands to them. It would also be nice if I could change the directory in one of them to the project directory. Is it even possible to pass arguments to an RC file? I know screen has the -c command for specifying different RC files, so that may work as a last resort, and I will just write a new one for my projects, or write a script to generate them.

screen -t home
split -v
focus right
screen -t home
focus left
split
split -v
focus left
screen -t home 

So in Summary:

1) How can I script startup commands in my splits

2) Any way to pass arguments to the rc file (project directory)

3) BONUS: It would also be great if someone could tell me how I can detach and reattach a session without losing the splits as well, I read somewhere it was not possible, but I am sure someone has a hacked together solution EDIT: Found the solution to this, from the screen FAQ

link|improve this question
feedback

2 Answers

Try tmux:

#!/bin/sh
session=${1:-unnamed}
tmux new -d -s "$session" "bash"
tmux split -t "$session" -h "bash"
tmux select-pane -t "$session" -L
tmux split -t "$session" -v "irb"
tmux select-pane -t "$session" -U
tmux split -t "$session" -h "python"
tmux attach -t "$session"

(See manual of tmux(1) for description of target-window and target-pane values accepted by -t)

link|improve this answer
thanks for the advice about tmux. I am using it right now to keep my splitted screen in tact when I detach. I may switch over to it entirely, I will have to play around with the code you gave. – Hortinstein Jun 28 '11 at 14:18
feedback
up vote 1 down vote accepted

After I saw some related SuperUser posts on the side I was able to accomplish like this (echos replace the command startups I need in case anyone wants to try it on their system):

screen -t home
split -v
focus down
screen bash -c 'echo "rails server"; exec bash -i'
split
focus down
screen bash -c 'echo "spork"; exec bash -i'
split -v
focus down
screen bash -c 'echo "sql output"; exec bash -i'
focus down
screen bash -c 'echo "autotest"; exec bash -i'

load this RC, and you will come up with this: enter image description here

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.