1

Most Linux operating systems have a package like command-not-found (http://packages.ubuntu.com/utopic/command-not-found), which provides suggestions when a shell command was not found, e.g. because the command was misspelt.

➜ puthon
No command 'puthon' found, did you mean:
 Command 'python' from package 'python-minimal' (main)
 Command 'python' from package 'python3' (main)

Is there similar functionality for OS X, e.g. through Homebrew?

3 Answers 3

5

I created Homebrew-command-not-found just for that. It works exactly as you would expect, and supports 5000+ Homebrew formulae. it works with Bash, Zsh, and Fish.

It’s currently limited to correct spellings, e.g.:

$ ghc
The program 'ghc' is currently not installed. You can install it by typing:
  brew install ghc
$ ghv
ghv: command not found

Install it with brew tap homebrew/command-not-found, then add the following line to your ~/.bashrc/~/.zshrc:

HB_CNF_HANDLER="$(brew --repository)/Library/Taps/homebrew/homebrew-command-not-found/handler.sh"
if [ -f "$HB_CNF_HANDLER" ]; then
  source "$HB_CNF_HANDLER";
fi

We’d welcome a PR for misspelling support, though.

4

Searching Google for "homebrew command-not-found" (without the quotes) one of the results was: Ubuntu’s command-not-found equivalent for Homebrew on OSX

I have not personally tried using it, so I cannot comment on how well it may work.

0
1

One option is to use zsh, which has a CORRECT option that will suggest commands with a "nearby" spelling. Personally, I use zsh and prezto, which results in this:

zsh and prezto auto correct

It's nice because the command is red while typing if it's not a valid program name, which means I usually catch the typo before I even press enter. Valid command names are green, though, so I know when I've typed it right.

zsh can be installed via homebrew, and then adding something like prezto on top of that is easy (it's just a git clone ..., ln -s ..., and chsh -s /usr/local/bin/zsh).

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .