forked from Homebrew/homebrew-command-not-found
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.sh
53 lines (43 loc) · 1.28 KB
/
handler.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#
# brew-command-not-found script for OS X
#
# Usage: Source it somewhere in your .bashrc (bash) or .zshrc (zsh)
#
# Author: Baptiste Fontaine
# URL: https://github.com/Homebrew/homebrew-command-not-found
# License: MIT
# Version: 0.2.0
#
if ! which brew > /dev/null; then return; fi
homebrew_command_not_found_handle() {
local cmd="$1"
# <from Linux Journal>
# http://www.linuxjournal.com/content/bash-command-not-found
# do not run when inside Midnight Commander or within a Pipe, except if on
# Travis-CI
if test -z "$CONTINUOUS_INTEGRATION" && test -n "$MC_SID" -o ! -t 1 ; then
[ -n "$BASH_VERSION" ] && \
TEXTDOMAIN=command-not-found echo $"$cmd: command not found"
return 127
fi
# </from Linux Journal>
local txt="$(brew which-formula --explain $cmd 2>/dev/null)"
if [ -z "$txt" ]; then
[ -n "$BASH_VERSION" ] && \
TEXTDOMAIN=command-not-found echo $"$cmd: command not found"
else
echo "$txt"
fi
return 127
}
if [ -n "$BASH_VERSION" ]; then
command_not_found_handle() {
homebrew_command_not_found_handle $*
return $?
}
elif [ -n "$ZSH_VERSION" ]; then
command_not_found_handler() {
homebrew_command_not_found_handle $*
return $?
}
fi