Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


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 -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

share|improve this question
up vote 4 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'
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

share|improve this answer

Try tmux:

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)

share|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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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