chucknorris: check for strfile dependency
Gives a better error message than "command not found: strfile", because
it's not obvious to many users that strfile is part of fortune.
Also handles the weird /usr/sbin install location for strfile on Cygwin.
Diff
1diff --git a/plugins/chucknorris/chucknorris.plugin.zsh b/plugins/chucknorris/chucknorris.plugin.zsh
2index 1cdc945d1347a4fdeada92b757b1982672af93d5..1dbb04ef0d08928841a906d4f112ffc6eeb9b38c 100644
3--- a/plugins/chucknorris/chucknorris.plugin.zsh
4+++ b/plugins/chucknorris/chucknorris.plugin.zsh
5@@ -1,11 +1,28 @@
6+# chucknorris: Chuck Norris fortunes
7+
8 # Automatically generate or update Chuck's compiled fortune data file
9-DIR=${0:h}/fortunes
10+# $0 must be used outside a local function. This variable name is unlikly to collide.
11+CHUCKNORRIS_PLUGIN_DIR=${0:h}
12+
13+() {
14+local DIR=$CHUCKNORRIS_PLUGIN_DIR/fortunes
15 if [[ ! -f $DIR/chucknorris.dat ]] || [[ $DIR/chucknorris.dat -ot $DIR/chucknorris ]]; then
16- strfile $DIR/chucknorris $DIR/chucknorris.dat
17+ # For some reason, Cygwin puts strfile in /usr/sbin, which is not on the path by default
18+ local strfile=strfile
19+ if ! which strfile &>/dev/null && [[ -f /usr/sbin/strfile ]]; then
20+ strfile=/usr/sbin/strfile
21+ fi
22+ if which $strfile &> /dev/null; then
23+ $strfile $DIR/chucknorris $DIR/chucknorris.dat >/dev/null
24+ else
25+ echo "[oh-my-zsh] chucknorris depends on strfile, which is not installed" >&2
26+ echo "[oh-my-zsh] strfile is often provided as part of the 'fortune' package" >&2
27+ fi
28 fi
2930 # Aliases
31 alias chuck="fortune -a $DIR"
32 alias chuck_cow="chuck | cowthink"
33+}
3435-unset DIR
36+unset CHUCKNORRIS_PLUGIN_DIR