Recently I've been hacking around on GNU screen. I've fixed a few bugs and added a few new features. One of the earliest features I added was the ability to source every file in a directory. One of the later additions was to add simple conditionals to the dotfile, via the new if primitive.
Today I had an epiphany moment. Rather than adding either of these two features I should have altered the behaviour in the far simpler manner.
If we allow ~/.tscreenrc to be an executable we immediately gain lots of things for free.
Consider this ~/.tscreenrc file:
#!/bin/sh for i in ~/.tscreen/*; do if [ -e $i ]; echo "source $i" fi done
That gives us the effect of a "source directory/" primitive. Similarly I can do complex tests without the need for an if primitive if I were to write this:
#!/bin/sh # common config cat ~/.tscreenrc.common # per host config? file=~/.tscreenrc.$(hostname --fqdn) if [ -e "$file" ]; then cat $file fi # if we have lynx define an alias for it + map it to a key if [ -x /usr/bin/lynx ]; then cat <<EOF # Surf the web with <Ctrl-a f> alias web screen -F -t web /usr/bin/lynx bind w web EOF fi
So as of v0.4.7 tscreen allows you to have your configuration file be:
- A normal file:
In which case it is parsed as you'd expect.
- An executable file:
In which case it is executed and the output is parsed.
The code change is trivial, just an extra stat call and the use of popen vs. fopen, but the payoff is significant.
ObFilm: Léon
Tags: tscreen 7 comments
I hope that there's a way for the system administrator to turn this feature off, globally, and that distros make this the default.