Hacking Thy Fearful Symmetry

Something Fishy

November 20th, 2013
perlfishperldocApp::GitGotDist::Zilla

This one will be terse. I just needed to share the bounty.

So after tackling that fish shell completion for perlbrew, I went on and churned a few more.

Perldoc

First and foremost, a port of one of my shiniest sparks: the perldoc bash completion that started here and has been improved on by Aristotle.

Dist::Zilla and Got

And then, just because it's so easy, I also went ahead and did the same for the sub-commands of both dzil and got.

And when I say easy, I mean easy. In both cases, the autocompletion is auto-munged from the 'help' output in a glorious one-liner. I'm not kidding, here's the content of dzil.fish:

eval (dzil help | perl                               \
-ne'print qq{complete -c dzil -a $1 -f -d \"$2\";\n} \
          if /(\w+):\s+(.*?)\s+$/')

If you want to join the fun, the syntax of complete is really not that complicated. If we take the same example and expand on the arguments used, we have:

complete -c dzil        # the command to auto-complete
         -a authordeps  # one, or many (whitespace-separated), options
         -f             # can't be followed by a filename 
         -d "do stuff"  # a description

There are more to know than that, like how to deal with subcommands and conditional suggestions, but that's already a good start.

In all cases, the fish files are in my environment repo, and should be PRed soon enough to the different projects they belong to. While I'm at it, I might also begin to gather those completions under a 'perl' umbrella within the Oh My Fish! project. Oh, and you can expect a MooX::Cmd (or maybe for MooseX::App::Cmd) plugin to auto-generate the fish autocomplete file pretty soon.

Enjoy!

Seen a typo or an error? Submit an edit on GitHub!