refactor(chucknorris): refresh plugin code

This commit is contained in:
Marc Cornellà 2021-10-05 16:45:49 +02:00
parent e5b9b80008
commit 53c9661b00
No known key found for this signature in database
GPG key ID: 0314585E776A9C1B
2 changed files with 18 additions and 24 deletions

View file

@ -1,8 +1,6 @@
# chucknorris # chucknorris
Chuck Norris fortunes plugin for oh-my-zsh. Perfectly suitable as MOTD. Chuck Norris fortunes plugin for Oh My Zsh. Perfectly suitable as MOTD.
**Maintainers**: [apjanke](https://github.com/apjanke) [maff](https://github.com/maff)
To use it add `chucknorris` to the plugins array in you zshrc file. To use it add `chucknorris` to the plugins array in you zshrc file.

View file

@ -1,28 +1,24 @@
# chucknorris: Chuck Norris fortunes
# Automatically generate or update Chuck's compiled fortune data file
# $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 # %x: name of file containing code being executed
if [[ ! -f $DIR/chucknorris.dat ]] || [[ $DIR/chucknorris.dat -ot $DIR/chucknorris ]]; then local fortunes_dir="${${(%):-%x}:h}/fortunes"
# For some reason, Cygwin puts strfile in /usr/sbin, which is not on the path by default
local strfile=strfile # Aliases
if ! which strfile &>/dev/null && [[ -f /usr/sbin/strfile ]]; then alias chuck="fortune -a $fortunes_dir"
strfile=/usr/sbin/strfile alias chuck_cow="chuck | cowthink"
# Automatically generate or update Chuck's compiled fortune data file
if [[ "$fortunes_dir/chucknorris" -ot "$fortunes_dir/chucknorris.dat" ]]; then
return
fi fi
if which $strfile &> /dev/null; then
$strfile $DIR/chucknorris $DIR/chucknorris.dat >/dev/null # For some reason, Cygwin puts strfile in /usr/sbin, which is not on the path by default
else local strfile="${commands[strfile]:-/usr/sbin/strfile}"
if [[ ! -x "$strfile" ]]; then
echo "[oh-my-zsh] chucknorris depends on strfile, which is not installed" >&2 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 echo "[oh-my-zsh] strfile is often provided as part of the 'fortune' package" >&2
return
fi fi
fi
# Aliases # Generate the compiled fortune data file
alias chuck="fortune -a $DIR" $strfile "$fortunes_dir/chucknorris" "$fortunes_dir/chucknorris.dat" >/dev/null
alias chuck_cow="chuck | cowthink"
} }
unset CHUCKNORRIS_PLUGIN_DIR