I've been trying to figure out the perfect way to set up my development environment for a while, and GNU Screen has been a huge help. You can find out about GNU Screen very easily on the web (and of course the man page), but when I wanted to figure out how to "save" my screen sessions I didn't find much help. It turns out that there's not really a practical way to do this for various reasons related to the shear complexity of terminals. You might be able to save sessions that worked in 95% of cases but caused severe problems in another 5%, so no one's bothered to implelment the hacky feature.
On the other hand, what you can do is configure a bunch of screenrc files that hold the commands you want to start up your sessions with. Here is a screenrc I use to start up a screen session suitable for hacking on Conquer-on-Contact:
screen -t "bzr"
stuff "bzr diff | colordiff"
screen -t "misc"
screen -t "devsvr"
stuff "cd ~/google_appengine^M"
stuff "./dev_appserver.py -p 8084 ~/shared/appengine/conquer-on-contact/root/"
screen -t "update"
stuff "cd ~/google_appengine^M"
stuff "./appcfg.py update ~/shared/appengine/conquer-on-contact/root/"
#change the hardstatus settings to give an window list at the bottom of the
#screen, with the time and date and with the current window highlighted
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %d/%m %{W}%c %{g}]'
vbell on
defscrollback 1024
startup_message off
autodetach on
defutf8 on
Here the screen -t "xxx" commands open up a new tab with the specified names, while the
stuff "some text here" commands actually put that text into the newly created tabs. One weird thing you might notice here are the ^Ms... You don't type those literally; you need to actually enter the control code. In vim you can do this by typing Control-V and then Control-M. If you add that to the end of the line a return will be sent and the command will be executed, otherwise it will just sit in the buffer and wait for you to hit enter (which is also pretty useful, actually...)
You can also use chdir command instead of this funny business with stuff and control codes, see an example. I think this method is more widely applicable, however.
Once you're done, save the file as screenrc and fire up the session with:
screen -S "SESSIONNAME" -c screenrc
If you're really lazy you could put that into a shell script so you only have to type something like ./st.sh after every reboot, or set it to fire automatically in detached mode so your screen sessions are just waiting for you to connect.
Later I'll play around with screen-profiles. I really love the little statuslines, now I'm just trying to get the current session name in there somehow...
3 comments: