a c d w

the unreasonable effectiveness of sh

the obligatory post about the new ssg i've written that is now building this website

Look, everybody writes a blog post about the static site generator they've written that's now going to power their website. I've written that blog post like, 4 or 5 times. I'm just going to write it now and get it over with here, so hang on to your butts.

What I'm not going to do in this blog post is describe how vienna (that's what the SSG I wrote and that is now powering this website is called) works. You can view that (or some semblance of it) at its git repo, as well as do all the other things you do with a git repo.

Instead, I'm going to take this opportunity to discuss why I chose to write an SSG in POSIX sh, using not much more than that and the sed command.

unk

The first foray I had into extremely minimalistic site generators was something I called unk.

unk is very simple, with the goal of being a functional SSG in under one kilobyte (un k). Its entire source code is this:

#!/bin/sh
alias c=cat q=test e=echo
rm -r O;mkdir -p O
q -f L||e '`c $F`'>L
q -d S&&cp -r S O/
X(){ eval "$(e 'c<<Z';c "$@";e;e Z)";}
for F in I/*
do q -f "$F"&&(e $F
N="${F#I/}"
T(){ sed 1q "$F";}
B(){ sed 1d "$F";}
X L>"O/${N%.*}")
done

There's some other stuff in there, like a small markup language called lht and layouts, templates, etc. You can see the whole gory thing at its repo.

The important bit, though, the bit that isn't just copying files from one well-known directory to another, is this:

X(){ eval "$(e 'c<<Z';c "$@";e;e Z)";}

That's the heart of unk, and it's the heart of vienna too. It's a clever little idea I found somewhere online (I cannot find where, it's very annoying) that allows you to use shell as a templating language.

but why shell models? ...sorry, I just couldn't resist

A lot of people like to hate on shell scripting. Whether it's dunking on it for its arcane quoting rules, its total lack of basic programming constructs like arrays, its weird scoping semantics, or some other problem, shell (specifically POSIX shell and its close derivatives) is universally panned.

I mean, I get it. It's not a great language. I've been getting more better at other more saner languages like LISP (lol), and yeah, bash and shell and the lot are pretty bad languages qua languages.

But here's the thing(s):

Maybe I just have a soft spot for shell scripting, but if you take a look at my git repos (not linking them here again; I've done it twice already, you're smart), you'll notice that the bulk are in some kind of shell script.

I just can't seem to quit it.

The thing about shell scripting is, it's the same language you're using every day at the command line. At its most pure, you're just telling the computer, hey, I'm busy—you take care of this for me, and that's all it does. I think I read somewhere, or if I didn't I definitely wouldn't be surprised if this were the history, that shell basically came to be organically, growing out of whatever need whoever was using it had at the time.

You know, the UNIX philosophy or whatever. The "do one thing and do it well" schtick was a retrocon tacked on later for credibility. It's really just ... people solving the problems they need solved right then.

Also, because it's the same language you're using to interact with your computer at the command line, you probably already know how to script in it. You just have to learn a few more things, like wrapping stuff in functions and the aforementioned arcane quoting rules. That makes software written in shell, or using shell heavily, dead simple to extend and mold to your needs.

so. vienna.

Right, so this is about vienna, that new shiny SSG I've written that's going to change the world, right? Here's what I think makes it my Platonic Ideal for an SSG: