diff options
author | Tuowen Zhao <ztuowen@gmail.com> | 2021-10-23 18:01:40 -0600 |
---|---|---|
committer | Tuowen Zhao <ztuowen@gmail.com> | 2021-10-23 18:01:40 -0600 |
commit | fad92c603be0ff36825cc53bf8c485d4b95c7869 (patch) | |
tree | 407fe826be62a3543b6feab4f3552f58575234de /plugins/chucknorris/chucknorris.plugin.zsh | |
parent | c674485e6b4abe313469900997d893d2940ee843 (diff) | |
parent | f1dd97bb2a9df55fae9b1ca26c829b9f8b290667 (diff) | |
download | zsh-fad92c603be0ff36825cc53bf8c485d4b95c7869.tar.gz zsh-fad92c603be0ff36825cc53bf8c485d4b95c7869.tar.bz2 zsh-fad92c603be0ff36825cc53bf8c485d4b95c7869.zip |
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'plugins/chucknorris/chucknorris.plugin.zsh')
-rw-r--r-- | plugins/chucknorris/chucknorris.plugin.zsh | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/plugins/chucknorris/chucknorris.plugin.zsh b/plugins/chucknorris/chucknorris.plugin.zsh index 1dbb04ef0..b90abe320 100644 --- a/plugins/chucknorris/chucknorris.plugin.zsh +++ b/plugins/chucknorris/chucknorris.plugin.zsh @@ -1,28 +1,24 @@ -# chucknorris: Chuck Norris fortunes +() { + # %x: name of file containing code being executed + local fortunes_dir="${${(%):-%x}:h}/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} + # Aliases + alias chuck="fortune -a $fortunes_dir" + alias chuck_cow="chuck | cowthink" -() { -local DIR=$CHUCKNORRIS_PLUGIN_DIR/fortunes -if [[ ! -f $DIR/chucknorris.dat ]] || [[ $DIR/chucknorris.dat -ot $DIR/chucknorris ]]; then - # 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 + # Automatically generate or update Chuck's compiled fortune data file + if [[ "$fortunes_dir/chucknorris" -ot "$fortunes_dir/chucknorris.dat" ]]; then + return fi - if which $strfile &> /dev/null; then - $strfile $DIR/chucknorris $DIR/chucknorris.dat >/dev/null - else + + # For some reason, Cygwin puts strfile in /usr/sbin, which is not on the path by default + 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] strfile is often provided as part of the 'fortune' package" >&2 + return fi -fi -# Aliases -alias chuck="fortune -a $DIR" -alias chuck_cow="chuck | cowthink" + # Generate the compiled fortune data file + $strfile "$fortunes_dir/chucknorris" "$fortunes_dir/chucknorris.dat" >/dev/null } - -unset CHUCKNORRIS_PLUGIN_DIR |