I see your point. Just out of curiosity, why in the world don't you use something other than psql for scripting? I mean, if you accessed the data from Perl or Python or $INSERT_YOUR_FAVORITE_SCRIPTING_LANGUAGE_HERE, you could do all of this stuff very easily without any contortions. I've always thought of psql as something that's fine for interactive use and goofy trivial scripting but not really suitable for serious work. I grant that you seem to be making it serve the purpose, but, man.
I'm coming to the realization that this sentiment, when applied to my primary application, is probably correct...
In my situation the scripting language of choice is Bash - which largely acts as glue for programs such as psql, pdftk, enscript, and the R language.
Being able to do more conditional work in psql would make setting up more robust scripts easier and without either losing transaction capabilities or session pooling for improved performance when large numbers of small commands are run in between flow control in done in bash.