Xana/ xana2/ 2007/ 09/ 29
Blagscroll

Joey, I find it the creepiest when I see my words scroll across my boss's monitor.

Posted Sat 29 Sep 2007 09:25:39 AM EDT Tags: 29
This Käse-Knoblauch Suppe is delicious, but what is that floating in it?

My next installment was going to cover a different topic, but Marty made a wish and unless Rajaton intercedes before this blog entry is over, the curriculum is going to careen off the track.

The relevant question is something like “Why do I have to type all that junk in when there's perfectly good --help output to parse?” and the relevant answer is something like “Yes. No. ROFLcows. Lamar.” This is somewhat easy when a program has well-behaved, sane-ish, GNU-style --help output.

Let's say you want completion for GNU ptx. Now you could go through and write a function using _arguments like you learned all about here, or you could just type

compdef _gnu_generic ptx

Suddenly you'll be able to complete options after ptx. You'll notice a few things as you perform your QA due diligence. It won't understand the subtleties of -G. It won't know what STRING and REGEXP and NUMBER mean, but then, neither do I.

It's possible to use _arguments to explain what WORDS IN ALL CAPITALS mean, but let's find a less BORING example.

Usage: nurmepuu [OPTION]... [FILE]
Drive Miss Nurmepuu

  -c, --compress=TYPE            apply this compression TYPE to the aircon
  -f, --force                    use force
  -s, --side=SIDE                drive on this SIDE of the road
  -u, --unbearability=LEVEL      tolerate this LEVEL of unbearability

So start out the way you have now learned instinctually.

#compdef nurmepuu

_arguments -- \

WAIT. WHAT'S THAT‽‽ The double hyphen-minus, contrary to the expectations of GNU and git users alike, means (are you ready for this?) parse the --help output and try to sanely complete long options. Now lets give it some hints so it isn't too braindead.

  '*=TYPE*:compression type:(gzip bzip2 lossy gainy pancakebatfish)' \
  '*=SIDE*:side of the road:(left right east west up)' \
  '*=LEVEL*:tolerance level:((japan\:haha radiohead\:hoho))'

There you go. The patterns on the left will be matched against the help output, and the completion actions on the right. The list in double parens are matches paired with descriptions (note the backslashed colons). Once more, the whole thing:

#compdef nurmepuu

_arguments -- \
  '*=TYPE*:compression type:(gzip bzip2 lossy gainy pancakebatfish)' \
  '*=SIDE*:side of the road:(left right east west up)' \
  '*=LEVEL*:tolerance level:((japan\:haha radiohead\:hoho))'
Posted Sat 29 Sep 2007 04:33:35 PM EDT Tags: 29