Image 01

Transneptune

beyond the Kuiper Belt, over the sea

Archive for December, 2012

Stupid bash tricks

Thursday, December 13th, 2012

Oh, hey, I have a blog. Who knew!

So, let me cross-post to it.

Stupid bash tricks with Kit La Touche!

When you want to run a long-running task in a terminal, and leave it and do other things, but not lose time between when it finishes and you check it, it’s time for audio!

So end your processes with this little snippet:

(some command); if [[ $? -eq 0 ]]; then echo ^G^G^G; else echo ^G^G^G^G^G; fi

(Remember, those are literal control-g bell characters. You get them by typing ctrl-v ctrl-g. There are other ways to make them that are easier to copy-paste, but this way’s easier to type quickly.)

That’ll ring the bell three times (good and attention-grabbing) if you succeed, and five times if you fail (even more attention-grabbing!).

The semi-colon after your command makes this run whether the previous command succeeds or fails; it’s the simplest way of chaining together bash commands. I’m writing this explanatory note because I’m so in the habit of chaining them with && (which makes the next command only run if the previous succeeded, through the magic of booleans and exit statuses), that I would might do that by mistake if I didn’t write out my rationale!

If you’re running it in a screen session (why aren’t you running a long-running process on a machine you’re ssh’ed into in screen?), then you may need to activate the audio bell instead of the visual bell. In which case, a quick ^a^g should toggle it on.

Tonight’s stupid bash tricks brought to you by insomnia and itchy mouth-stitches.