Blast from the past: Sniglets

I’m reminded today of Sniglets. I grew up in the 1980s watching lots of HBO, so Rich Hall’s little segments from Not Necessarily the News occupy a special place in some dark corner of my cerebrum. I can still remember to this day:

  • flen – the yucky stuff that accumulates under the cap of a ketchup bottle.
  • accello-yellow – someone who speeds up when they see a yellow traffic light

I just thought of a sniglet of my own. It’s a term for when you spend a couple of hours writing fancy little bash functions that do really specialized things that are fun but perhaps of questionable use.

I call this: “bashturbation”.

Side effect of the switch

I noticed one annoying side effect of the switch. I used to be able to hold down the control key while tapping the trackpad on my PowerBook to get the equivalent of a right click – e.g.: context menus in Firefox and Finder. Holding down my new control key (the key formerly known as caps lock) and tapping the trackpad doesn’t work. Curiously, holding the key down and pressing the trackpad button does work though. I almost never touch that button though.


Anybody figure out a way to make it work?


Fallout Boy

I guess the lyrics of that annoying Fallout Boy song are in fact English (I was starting to have doubts):

We’re going down, down in an earlier round
And Sugar, we’re going down swinging
I’ll be your number one with a bullet
A loaded god complex, cock it and pull it

It’s still annoying though.


The one drawback of the recent warm and dry Bay Area weather is that it looks like the beginning of spider season…

This morning we got our first use of our BugZooka. A little spider in the bedroom was sucked and then let free outside. Sure beats our previous “spray bottle and old shoe” method. Much quicker and easier and nothing to clean up and I dare say that the spiders probably like it better too.



Made the switch

After deliberating for a while, I’ve finally done it.

Yes, that’s right. Like a true Emacs geek, I’ve swapped my “caps lock” and “control” keys. I could see that this could be nice once I get accustomed to it, though for now I keep reaching for the “control” and turning on “caps lock”. I had almost contemplating making both of them act as “control” but decided against it as that will probably just stop me from learning properly.

Doing this on a Mac once required extra software like uControl, fKeys, or DoubleCommand, but now in Tiger you can just do it in the Keyboard & Mouse System Preferences panel.


Having a bash with bash

Let’s say we want to write a command that allows you to take the output of the previous command and stick it in your editor so you can page through it, save it, email it, etc.

One way to do it is with bash’s “process substitution” feature. Try this:

$ ls -l
$ cat <($(tail -1 $HISTFILE)) | vim -

One problem with this is it won’t work if you change “vim” to “emacs”, because Emacs doesn’t like to read stdin. I tried all kinds of stuff including “emacs -nw -t /dev/tty /dev/stdin” and such.

Well, here’s an even more general solution:

with-temp-file ()
    local _prefix=$1; shift
    local _tmpfile_var=$1 ; shift
    local ${_tmpfile_var}=$(mktemp -t ${_prefix})
    eval local _tmpfile_value=\${$_tmpfile_var}
    eval "$@"
    rm ${_tmpfile_value}

edlo ()
    with-temp-file "edlo" tmpfile \
        '$(tail -1 $HISTFILE) > $tmpfile && $EDITOR $tmpfile'

Actually for bash versions 2 and up, it turns out we can clean this up a tad using the new syntax for indirect references to variables:

---   Sat Apr 29 15:19:53 2006
+++     Sat Apr 29 15:25:11 2006
@@ -3,7 +3,7 @@
     local _prefix=$1; shift
     local _tmpfile_var=$1 ; shift
     local ${_tmpfile_var}=$(mktemp -t ${_prefix})
-    eval local _tmpfile_value=\${$_tmpfile_var}
+    local _tmpfile_value=${!_tmpfile_var}
     eval "$@"
     rm ${_tmpfile_value}

This should work in any editor, including X11 editors since we’re not using stdin. And the with-temp-file function is a general utility function that could be used for other stuff. Here’s another function that uses it:

eoo () 
    local _cmd="$@";
    with-temp-file "eoo" tmpfile '$_cmd > $tmpfile && $EDITOR $tmpfile'

This one is when you already know that you want to capture the output of a particular command – e.g.:

$ eoo ls -l
$ eoo finger


Unix Power Tools, Third Edition