Screen Textmate Bundle
When working on a rails project I usually have script/server, script/console and autotest all running in GNU Screen. Jamie Flournoy has already described why using GNU screen is better than plain old Terminal Tabs.
I’ve put together a Screen Textmate Bundle to make it easy to configure and open per project screen sessions.
Installation
Run this:
cd ~/Library/Application\ Support/TextMate/Bundles
git clone git://github.com/mocoso/screen.tmbundle.git Screen.tmbundle
Set up your screen configuration for a project
Create a .screenrc file in your project directory if you want to specify a particular configuration for your project.
For example for a Ruby on Rails project you might create a .screenrc file in your project directory like this
# Have the server running in screen 1
#
# Stuff is used so that when you exit the stuff-ed program, you drop back
# to the bash shell for that screen instead of immediately exiting that
# screen. This is useful for "^c, up-arrow, enter" restarting of programs.
screen -t server 1
stuff "script/server\012"
# Have autotest running in screen 2
screen -t autotest 2
stuff "autotest\012"
# Have the console running in screen 3
screen -t console 3
stuff "script/console\012"
# Finally have a command line prompt at the project root in screen 4
screen -t project_root 4
Usage
Use this bundle’s ‘Start Session’ command (ctrl-shift-s) to start (or reconnect to) your project’s screen session.
If you have created a .screenrc file in your project directory then this will be used to initialize the new session.
Update (14th Sep 2008)
On Jonathon Palardy’s suggestion I’ve added a ‘Send to Screen’ command (ctrl-alt-c) that copies selected text (or current line if no selection made) to your project’s screen session. If you have multiple windows open in the session then it will paste to the currently selected window.
Update (22nd Jan 2009)
If you want similar functionality without learning screen then check out Nick Rutherford’s Rails Workbench
November 2nd, 2008 at 6:29 am
Very cool – exactly what I was looking for after seeing Rich Hickey’s clojure demo with emacs+slime+swank+clojure.
I now retrospectively resent every cli session that I haven’t been controlling from textmate.
A couple of small points – none of the keyboard shortcuts seem to coincide with what you describe (ctrl-a to start session and ctrl-alt-c to send a command), appending a carriage return makes sending commands a little more convenient and for some reason my .screenrc wasn’t getting picked up (haven’t looked into it).
November 2nd, 2008 at 7:25 am
Glad you like it.
Perhaps they are clashing with another bundle you have. Try changing the keyboard shortcuts using Textmate’s Command Editor (look in Bundles -> Bundle Editor -> Edit Commands menu) and see if that helps.
Also this will either use a .screenrc in your project folder (if there is one) OR your .screenrc in your homefolder. Which one of these is not being picked up when you expect it to be?
March 4th, 2009 at 10:30 pm
I like the concept, I would suggest changing the default keystroke to something other than ^A as ^A is the OS X global “go to beginning of line” (as per emacs) and I use it a lot when text editing. I have set mine to control-command-A. Also, is there a way when opening a new Terminal window, to have it attach to to a present window in a new tab? I generally have more than one rails project I am working on, so I generally organize them with tabs for projects and screen for each shell / tool I need for that project.
thanks, this is a great bundle
March 5th, 2009 at 6:25 am
Glad you like it and thanks for your suggestions for improvements.
I’ve switched the default keystroke for the screen command.
I use iTerm rather than Terminal and for iTerm the bundle already supports opening a new tab. So you could either switch to using iTerm, or fork the bundle on Github and modify it to support this behaviour in Terminal.