I have the following bash script to set up a screen session with four windows from the command line in 13.10. Comments indicate what I think it ought to do.
screen -dmS mysession # start screen, name the session 'mysession' screen -S mysession -p 0 -X exec echo -ne "\ekserver\e\\" # name the first window 'server' screen -S mysession -p 0 -X exec screen # start a second window screen -S mysession -p 1 -X exec echo -ne "\ekvim 1\e\\" # name second window 'vim 1' screen -S mysession -p 1 -X exec screen # start a third window screen -S mysession -p 2 -X exec echo -ne "\ekvim 2\e\\" # rename third window 'vim 2' screen -S mysession -p 2 -X exec screen # start a fourth window screen -S mysession -p 3 -X exec echo -ne "\ekconsole\e\\" # name fourth window 'console'
Every second or third time I run it, I get exactly what I want: four windows, each named as I have them here. The rest of the time I get anywhere between one and four windows, some of them named correctly, other times with the default, 'bash' name. Why am I seeing this behaviour, and how do I fix it?
Between each time I run it I make sure the screen session has ended, by typing exit in each window and checking screen -ls to see that there are no screen sessions active.
From the comment by "chris" on this page I now have a project specific dotfile that I invoke from
source .projectscreenrc - when the file is present it contains
screen -t commands as suggested in glenn jackman's answer. When it is not present screen runs as normal. I'm still not sure why this works and why my original approach didn't, but this is much cleaner.