03Sep

Figlets From Hell

Posted by Elf Sternberg as programming

Anyone who’s ever worked with me knows that I’m inordinately fond of figlet, a program that creates banner letters out of ordinary text.  It works best as an example:

# figlet -w 200 -fsmall Here Be Dragons
 _  _               ___        ___
| || |___ _ _ ___  | _ ) ___  |   \ _ _ __ _ __ _ ___ _ _  ___
| __ / -_) '_/ -_) | _ \/ -_) | |) | '_/ _` / _` / _ \ ' \(_-<
|_||_\___|_| \___| |___/\___| |___/|_| \__,_\__, \___/_||_/__/
                                            |___/

I have these scattered throughout my source code, mostly to indicate to the user where he or she is, and what class and related material they’ll be working on. Since I work in Rich Internet Application development using Django, I frequently have many small applications, and I often have multiple stacks (Server Side, Templates, Javascript, and CSS) for each application, so I end up with lots of little bundles, and having these big roadsigns helps me know where I am. They show up nicely in Eclipse and Emacs.

But I get tired of having to transport the output of figlet into my code at any given point. So I wrote a little program to do it for me. It output python-style comments by default, and if you prefix your text with // it’ll spit out Javascript-style one-line comment lines instead. But the beauty of it is that second line, which automagically puts the comment into your primary selection clipboard– that’s the one pasted by your middle mouse button. After running autofig, the figlet is in your mouse button clipboard and you can drop it anywhere you want.  The figlet font “small” is hard-coded, but you can pick whatever you want.  Slant and eftiwater are lovely figlet fonts.  I’ve set the width to 200; that ought to be enough for anyone.  It outputs the text to the console so you can assess its look before you paste it.    Beauty, eh?

#!/bin/bash

P="#"
if [ $1 == "//" ]; then
  P="\/\/"
  shift
fi

figlet -w 200 -fsmall $* | sed 's/^/'$P' /'
figlet -w 200 -fsmall $* | sed 's/^/'$P' /' | xclip -in -selection primary

Postscript: Typing ‘figlet’ consistently proved to be harder than I thought. Years of typing ‘gif’ has poisoned my typing rhythm.

Comment Form

Subscribe to Feed

Categories

Calendar

September 2009
M T W T F S S
« Aug   Oct »
 123456
78910111213
14151617181920
21222324252627
282930