GNU Screen Tip! Multiple configuration files
Not many people have heard of GNU Screen. (Wikipedia) And to those who have heard it, not many actually use it. For people not familiar with screen think of it now as tabs for terminals. But it’s more powerful than that, so perhaps think of it as lsd-induced-super-intense-spectacular-tabs.
I’m a heavy user of screen actually, and use it in combination with vim, as it provides me with speed.
But there is a shortcoming of screen which, either I couldn’t figure out, or difficult to google. So what I did instead was created a script to help me out.
The scenario is that I have several projects, say a Drupal, and a Ruby on Rails project.
With screen you can start off with multiple tabs open and settings optimized for your needs. Well I had different needs, different needs for each project.
Screen saves its configuration files in a screenrc configuration file, and the user default configuration of screenrc is saved in ~/.screenrc. I wanted a individual screenrc for each of my project. I initially thought screen was able to load both the default and unique screenrc, so I ran:
[code]
$ screen -c ~/screenrc/drupal
[/code]
Didn’t work, as it didn’t load my default screenrc settings. I continued trying.
[code]
$ screen -c ~/.screenrc -c ~/screenrc/drupal
[/code]
Another failure.
Next was google, but that wasn’t too helpful as well. Great choice to call it “screen”, such a generic name/word makes it difficult to search for.
What next then? Yes I could if I wanted to hacked the GNU Screen source, and solve the problem. But I’m not a C guru, not exactly my area of expertise, plus I wanted to do it quickly.
So what I did was make a Ruby script which parses my default screenrc file, and my project’s screenrc file. This would include the default file contents into the screenrc file automagically.
You can download the script here. Don’t forget to make it executable.
The script works by entering:
[code]
$ ~/path-to-script/generate_screenrc.rb project
[/code]
Where project is the file containing project specific screenrc settings.
So what now? Well now have I have a folder called “screenrc” in home directory and I fire up screen with:
[code]
$ screen -c ~/screenrc/project
[/code]
Where project is the project I want to load.
You don’t have to use this for coding, perhaps you might want to have a screen instance with monitoring programs running.
In my case I would then have a file called ~/screenrc/monitor and maybe include this configuration:
[code]
screen -t top 0
screen -t iptraf 1
screen -t irssi 2 irssi
screen -t nload 3 nload
[/code]
Customize it however you want.
Another Tip
For VIM users, include this vim modeline, in your default screenrc settings, and your produced screenrc file will have screen’s syntax enabled.
[code]
# vim: syntax=screen
[/code]
For more GNU Screen tips have a look at their manual, or the Gentoo Wiki. I particularly like the visualization of the “tabs”.
Instead of going through all this I could probably use an actual IDE…


