53c9661b003b91e8af356c3ecbb95a025ffcd412

Author
Marc Cornellà <hello@mcornella.com>
Committer
Marc Cornellà <hello@mcornella.com>
Date

Message

refactor(chucknorris): refresh plugin code

Diff

 1diff --git a/plugins/chucknorris/README.md b/plugins/chucknorris/README.md
 2index 35f98918058d8c90bf1c2184106147be5f5f617e..b51875de9e52312a04f705ebfdda814bf3ac4a98 100644
 3--- a/plugins/chucknorris/README.md
 4+++ b/plugins/chucknorris/README.md
 5@@ -1,8 +1,6 @@
 6 # chucknorris
 7 
 8-Chuck Norris fortunes plugin for oh-my-zsh. Perfectly suitable as MOTD.
 9-
10-**Maintainers**: [apjanke](https://github.com/apjanke) [maff](https://github.com/maff)
11+Chuck Norris fortunes plugin for Oh My Zsh. Perfectly suitable as MOTD.
12 
13 To use it add `chucknorris` to the plugins array in you zshrc file.
14 
15diff --git a/plugins/chucknorris/chucknorris.plugin.zsh b/plugins/chucknorris/chucknorris.plugin.zsh
16index 1dbb04ef0d08928841a906d4f112ffc6eeb9b38c..b90abe3209265af522f9dd3b05ba5df3a5baf3c8 100644
17--- a/plugins/chucknorris/chucknorris.plugin.zsh
18+++ b/plugins/chucknorris/chucknorris.plugin.zsh
19@@ -1,28 +1,24 @@
20-# chucknorris: Chuck Norris fortunes
21+() {
22+  # %x: name of file containing code being executed
23+  local fortunes_dir="${${(%):-%x}:h}/fortunes"
24 
25-# Automatically generate or update Chuck's compiled fortune data file
26-# $0 must be used outside a local function. This variable name is unlikly to collide.
27-CHUCKNORRIS_PLUGIN_DIR=${0:h}
28+  # Aliases
29+  alias chuck="fortune -a $fortunes_dir"
30+  alias chuck_cow="chuck | cowthink"
31 
32-() {
33-local DIR=$CHUCKNORRIS_PLUGIN_DIR/fortunes
34-if [[ ! -f $DIR/chucknorris.dat ]] || [[ $DIR/chucknorris.dat -ot $DIR/chucknorris ]]; then
35-  # For some reason, Cygwin puts strfile in /usr/sbin, which is not on the path by default
36-  local strfile=strfile
37-  if ! which strfile &>/dev/null && [[ -f /usr/sbin/strfile ]]; then
38-    strfile=/usr/sbin/strfile
39+  # Automatically generate or update Chuck's compiled fortune data file
40+  if [[ "$fortunes_dir/chucknorris" -ot "$fortunes_dir/chucknorris.dat" ]]; then
41+    return
42   fi
43-  if which $strfile &> /dev/null; then
44-    $strfile $DIR/chucknorris $DIR/chucknorris.dat >/dev/null
45-  else
46+
47+  # For some reason, Cygwin puts strfile in /usr/sbin, which is not on the path by default
48+  local strfile="${commands[strfile]:-/usr/sbin/strfile}"
49+  if [[ ! -x "$strfile" ]]; then
50     echo "[oh-my-zsh] chucknorris depends on strfile, which is not installed" >&2
51     echo "[oh-my-zsh] strfile is often provided as part of the 'fortune' package" >&2
52+    return
53   fi
54-fi
55 
56-# Aliases
57-alias chuck="fortune -a $DIR"
58-alias chuck_cow="chuck | cowthink"
59+  # Generate the compiled fortune data file
60+  $strfile "$fortunes_dir/chucknorris" "$fortunes_dir/chucknorris.dat" >/dev/null
61 }
62-
63-unset CHUCKNORRIS_PLUGIN_DIR