diff --git a/plugins/chucknorris/chucknorris.plugin.zsh b/plugins/chucknorris/chucknorris.plugin.zsh index 1cdc945d..1dbb04ef 100644 --- a/plugins/chucknorris/chucknorris.plugin.zsh +++ b/plugins/chucknorris/chucknorris.plugin.zsh @@ -1,11 +1,28 @@ +# chucknorris: Chuck Norris fortunes + # Automatically generate or update Chuck's compiled fortune data file -DIR=${0:h}/fortunes +# $0 must be used outside a local function. This variable name is unlikly to collide. +CHUCKNORRIS_PLUGIN_DIR=${0:h} + +() { +local DIR=$CHUCKNORRIS_PLUGIN_DIR/fortunes if [[ ! -f $DIR/chucknorris.dat ]] || [[ $DIR/chucknorris.dat -ot $DIR/chucknorris ]]; then - strfile $DIR/chucknorris $DIR/chucknorris.dat + # For some reason, Cygwin puts strfile in /usr/sbin, which is not on the path by default + local strfile=strfile + if ! which strfile &>/dev/null && [[ -f /usr/sbin/strfile ]]; then + strfile=/usr/sbin/strfile + fi + if which $strfile &> /dev/null; then + $strfile $DIR/chucknorris $DIR/chucknorris.dat >/dev/null + else + echo "[oh-my-zsh] chucknorris depends on strfile, which is not installed" >&2 + echo "[oh-my-zsh] strfile is often provided as part of the 'fortune' package" >&2 + fi fi # Aliases alias chuck="fortune -a $DIR" alias chuck_cow="chuck | cowthink" +} -unset DIR \ No newline at end of file +unset CHUCKNORRIS_PLUGIN_DIR