so

Tab completion after colon

Volume 10, Issue 28; 20 Aug 2026

Tab completion is great. But it doesn’t work by default after a colon. Unless you do this.

Since long before my time, the Saxon products have used a colon to delimit command line arguments from their values. For example, you specify the source document mydoc.xml with the command line argument -s:mydoc.xml.

Because Saxon does it that way, and because I’d like to hold onto whatever tattered shreds of sanity I have left, I also do it that way in XML Calabash and NineML.

That’s fine, except that it breaks tab completion.

If you type -s my<TAB> on the command line, as a program argument, most shells will do completion of some sort on the my part. If the only file that begins with my in the directory is mydoc.xml, then tab completion will fill it in for you. (If more than one file begins with my, you might get the first one, or completion up to the point where they differ, or a menu, it depends and I don’t know off the top of my head on what.)

Unfortunately, if you type -s:my<TAB> on the command line, nothing happens.

I was recently asked if I could tweak the command line parsing on NineML so that tab completion would work. I probably could, but this was my impetus to finally investigate if completion after a colon was possible, and if so, how.

For the shell I use, zsh, the answer is remarkably simple. Just add these lines to your ~/.zshrc file:

function aftercolon() {
  compset -P '*:'
  compset -S ':*'
  _default -r '\-\n\t /:' "$@"
}

autoload -Uz compinit
compinit
compdef aftercolon coffeepot saxon xmlcalabash

Replace “coffeepot”, “saxon”, and “xmlcalabash” with whatever shell scripts or aliases you use to run those commands (and add any others that you’d like to have completion-after-colon on).

I tried to work out how to do it with other shells. Anecdotal evidence suggersts that it’s possible bash, but I couldn’t work out exactly how. I’d be surprised if it isn’t also possible in other Unix shells. I haven’t a clue about PowerShell.

If anyone sends me the recipes, I’ll post em.

#NineML #XML Calabash

Please provide your name and email address. Your email address will not be displayed and I won’t spam you, I promise. Your name and a link to your web address, if you provide one, will be displayed.

Your name:

Your email:

Homepage:

Do you comprehend the words on this page? (Please demonstrate that you aren't a mindless, screen-scraping robot.)

What is seven plus three?   (e.g. six plus two is 8)

Enter your comment in the box below. You may style your comment with the CommonMark flavor of Markdown.

All comments are moderated. I don’t promise to preserve all of your formatting and I reserve the right to remove comments for any reason.