Natural Language and Scripting

Posted 1462320000 seconds after the Unix epoch

This post by Justin Duke reminded me of something unusual I have been doing recently.

A couple of weeks ago, I reflected on the fact that we use a considerable degree of restriction when “talking” to our phones (something that I do very little of). For example, we will make sure to say, “alarm”, or “wake me” — and we usually specify AM or PM as well. Something like, “Ok Google, make sure I get up at 8, and DON’T allow me to snooze” is probably not going to work.

[As an aside, apart from setting alarms, I’m not a big user of voice recog via “Ok, Google”. I’m secretly worried that their voice recognition will fail catastrophically at some point, and end up ordering 50 inflatable pink hippopotamuses from Google Express. Thankfully, this hasn’t happened. Yet.]

So, my revolutionary thought goes, why not do something similar and use more natural language for scripts? To try this out, I rewrote a bunch of scripts that need me to type in well-formed phrases or sentences into the terminal. Now I understand that for the seasoned Unix user who can recite the flags to tar off the top of their head, this will seem like absolute heresy – but it appears to work well for me.

xkcd: tar (via xkcd.com)

xkcd: tar (via xkcd.com)

For example, we have a bunch of common lab resources at work that we ‘reserve’ for ourselves, or free into a common pool as necessary. A script, for example, to take a resource from User A to User B might be invoked something like this: ./change_script user1 user2 …and I can never remember which one is the “from” user is and which one is the “to” user.

Since I am usually the “from” user while taking and the “to” user while giving, I simplified this into two simple scripts that are invoked as I would say them in real life.

# Take a resource from someone else's pool
take [resource]

# Give a resource to someone else from your pool:
give [resource]

For some more complicated scripts, I introduced semantic-only arguments, that made my script invocation look as follows:

put [resource] in group X

(which traditionally would have been called with something like

put --group X [resource]

I am going to try and keep this up for my own scripts. I would take the overhead of typing a new word over the overhead of remembering how a script is called, or (way worse) reading it and figuring out which argument goes where.


❧ Please send me your suggestions, comments, etc. at comments@mandarg.com