[JT] Jochen Topf's Blog
Wed 2014-07-23 19:39

Osmium Command Line Completion

When I started using the ZSH shell years ago, it was because of its superior command line completion features. Since then, the Bash shell has improved a lot, and probably has the same features, but I am used to ZSH now. And when a command doesn’t have completion it feels cumbersome to use. So, of course, I wanted to have completion for the osmium tool.

Command line completion has come a long way and being able to not only complete path names, but names of options, host names, file names on remote systems, autocorrecting typos, etc. has made the life of shell users much easier. But setting up completion for a new command has never been easy for the developer and the zsh documentation on the subject, while being quite extensive, isn’t really that easy to understand. And it doesn’t help that a few versions back they completely changed the completion system, so a lot of the stuff you find on the Internet is outdated. But I found this excellent introduction, read zsh’s manpages and online manual and dug through existing completion configurations (on my system under /usr/share/zsh/functions/Completion/).

And after a lot of trial and error the completion for Osmium (mostly) works. Turns out once you get the hang of it, it isn’t really that complicated. You can see the resulting file. The configuration knows about osmium’s subcommands, all the command line options in short and long form and about file name suffixes for OSM files. It gives helpful hints when hitting the TAB key what options are allowed or how the next parameter should be formatted. Quite nifty. And so, as intended, it makes using the Osmium command much easier. This will be even more important in the future when more functions are added to it.

Oh, and when you build and install the (inoffical) Osmium Debian package, it puts the configuration in the right place where your ZSH finds it.

Tags: osmium · zsh