From f8f360c800583769f606b563a6254d3019620e59 Mon Sep 17 00:00:00 2001 From: Jan Segre Date: Fri, 31 Oct 2014 18:33:41 -0200 Subject: [PATCH] Work on OS X with bfontaine/brew-command-not-found. --- .../command-not-found.plugin.zsh | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/plugins/command-not-found/command-not-found.plugin.zsh b/plugins/command-not-found/command-not-found.plugin.zsh index f3d7ec2df..45c798904 100644 --- a/plugins/command-not-found/command-not-found.plugin.zsh +++ b/plugins/command-not-found/command-not-found.plugin.zsh @@ -7,3 +7,40 @@ # Arch Linux command-not-found support, you must have package pkgfile installed # https://wiki.archlinux.org/index.php/Pkgfile#.22Command_not_found.22_hook [[ -e /usr/share/doc/pkgfile/command-not-found.zsh ]] && source /usr/share/doc/pkgfile/command-not-found.zsh + +# brew-command-not-found script for OS X +# +# Original author: Baptiste Fontaine +# URL: https://github.com/bfontaine/brew-command-not-found +# License: MIT +# Version: 0.1.1 +if [ ! -z "$(which brew)" ]; then + local formula_path="$(brew --prefix)/Library/Formula" + + command_not_found_handler() { + + # + # http://www.linuxjournal.com/content/bash-command-not-found + + export TEXTDOMAIN=command-not-found + + # do not run when inside Midnight Commander or within a Pipe + if test -n "$MC_SID" -o ! -t 1 ; then + return 127 + fi + + # + + local f=$(grep -lI -E "bin\.install..*\b$1\b(\"|')" $formula_path/*.rb 2>/dev/null) + + if [ -z "$f" ]; then + return 127 + fi + + f=${f##*/} + f=${f%%.rb} + + echo "The program '$1' is currently not installed. You can install it by typing:" + echo " brew install $f" + } +fi