Zsh, grails and “incorrect correction”

I’ve been using grails to prototype a crud application today and I thought I’d share some annoyances that I had in getting my terminal just the way that I like it.  Firstly I should say that I’m using Zsh with oh-my-ssh which gives you lots of nice things on top of the shell.

Get command completion for grails

oh-my-zsh comes with some nifty plugins, one of which will allow give you grails command completion on the terminal. All you need to do is to open your zsh configuration file…

vim ~/.zshrc

…and then add grails to the list of active plugins

# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
plugins=(git osx grails)

You can then close and reopen the terminal, or re-read the configuration…

source ~/.zshrc

No, I really don’t mean ‘rails’

The next annoyance is that zsh can take some time to learn that your newly installed ‘grails’ command actually exists.  Until that happens you’ll get something like this (assuming you have correction enabled globally)

zsh: correct 'grails' to 'rails' [nyae]?

The options it is giving you here are pretty straightforward:

  • n for “no“. This will run the command you entered (“grails”)
  • y for “yes“. This will run the command zsh suggested (“rails”)
  • a for “abort“. This will abort the command and return you to an empty terminal prompt
  • e for “edit“. This will return you to a terminal prompt with “grails” still typed, should you wish to correct it manually.

There are a couple of ways to get zsh to realise that “grails” is valid though.  The first is to tell it to update its hash of legal commands:

hash -fr

If you don’t want to do that or if it doesn’t work you can also alias the command and prepend “nocorrect”.  Open up your zsh configuration file again…

vim ~/.zshrc

…and add this line

alias grails='nocorrect grails'

Finally reload the configuration file again.

source ~/.zshrc

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s