Sunday, April 22, 2007

Z-Shell command completing

Alright, I admit it. I've been using the z-shell for a few years now and have never really dug in beyond what you'd find in bash. So it finally dawned on me to figure out how to create my own completions.

Granted, I didn't dig in too far beyond the basics but still it has been extremely handy.

For any commonly used command line util get the list of commands:
grails help

Then make a line in your .zshrc (found in your home directory) that maps those commands to the grails keyword:


compctl -k '(bootstrap bug-report clean compile console create-app create-controller create-domain-class create-job create-plugin create-script create-service create-tag-lib create-test-suite generate-all generate-controller generate-views generate-webtest help init install-dojo install-plugin install-templates package package-plugin package-plugins run-app run-webtest shell test-app upgrade war)' grails


compctl can do much more powerful tricks but for me just mapping the given array of words is great.

Now I can simply type 'grails c[tab]' to list all the commands that start with 'c'

I've also made a similar array for Subversion:

compctl -k '(add blame cat checkout cleanup commit copy delete diff export help import info list log merge mkdir move propdel propedit propget proplist propset resolved revert status switch update)' svn

The best part is if you type 'svn help [tab]' you'll still get the list of keywords so you can easily get detailed help.

Good stuff.

There is a bash plugin available to help program similar completions.

No comments: