Tab Completion After Colon

speckx2 pts0 comments

Tab completion after colon[First][Previous][Info]

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

Because Saxon does it that way, and because I’d like to hold onto whatever<br>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 on the command line, as a program argument, most<br>shells will do completion of some sort on the my part. If the only file<br>that begins with my in the directory is mydoc.xml, then tab completion will<br>fill it in for you. (If more than one file begins with my, you might get the<br>first one, or completion up to the point where they differ, or a menu, it<br>depends and I don’t know off the top of my head on what.)

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

I was recently asked if I could tweak the command line parsing on NineML so that<br>tab completion would work. I probably could, but this was my impetus to<br>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<br>to your ~/.zshrc file:

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

autoload -Uz compinit<br>compinit<br>compdef aftercolon coffeepot saxon xmlcalabash

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

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

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

#NineML #XML Calabash<br>Please provide your name and email address.<br>Your email address will not be displayed and I won’t spam you,<br>I promise. Your name and a link to your web address,<br>if you provide one, will be displayed.<br>Your name :<br>Your email :<br>Homepage:<br>Do you comprehend the words on this page? (Please demonstrate that you aren't a mindless, screen-scraping robot.)<br>What is eight times eight?

(e.g. six plus two is 8)

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

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

completion colon command line after saxon

Related Articles