Browse Source

feat(plugins): add hitchhiker plugin (#5117)

Luiz Pericolo 8 years ago
parent
commit
d8b3e115e9

+ 1 - 0
plugins/hitchhiker/.gitignore

@@ -0,0 +1 @@
+fortunes/hitchhiker.dat

+ 44 - 0
plugins/hitchhiker/README.md

@@ -0,0 +1,44 @@
+# hitchhiker
+
+This plugin adds quotes from The Hitchhiker's Guide to the Galaxy, from Douglas Adams.
+
+To use it, add `hitchhiker` to the plugins array in your zshrc file:
+
+```zsh
+plugins=(... hitchhiker)
+```
+
+## Aliases
+
+- `hitchhiker`: displays a quote from the book using `fortune`.
+- `hitchhiker_cow`: displays a quote from the book using `cowthink`.
+
+```console
+$ hitchhiker_cow
+ _______________________________________
+( "OK, so ten out of ten for style, but )
+( minus several million for good        )
+( thinking, yeah? "                     )
+ ---------------------------------------
+        o   ^__^
+         o  (oo)\_______
+            (__)\       )\/\
+                ||----w |
+                ||     ||
+```
+
+## Requirements
+
+- `fortune` and `strfile`.
+- `cowthink` if using the `hitchhiker_cow` command.
+
+## Credits
+
+Fortune file: Andreas Gohr <andi@splitbrain.org> ([splitbrain.org](https://www.splitbrain.org/projects/fortunes/hg2g))
+
+Spelling and formatting fixes: grok@resist.ca
+
+Original quotes from:
+
+- https://web.archive.org/web/20120106083254/http://tatooine.fortunecity.com/vonnegut/29/hitch/parhaat.html
+- https://web.archive.org/web/20011112065737/http://www-personal.umd.umich.edu/~nhughes/dna/faqs/quotedir.html

File diff suppressed because it is too large
+ 275 - 0
plugins/hitchhiker/fortunes/hitchhiker


+ 23 - 0
plugins/hitchhiker/hitchhiker.plugin.zsh

@@ -0,0 +1,23 @@
+HITCHHIKER_DIR="${0:h}/fortunes"
+
+# Aliases
+alias hitchhiker="fortune -a $HITCHHIKER_DIR"
+alias hitchhiker_cow="hitchhiker | cowthink"
+
+() {
+  # Don't generate hitchhiker.dat if it exists and is up-to-date
+  if [[ -f "$HITCHHIKER_DIR/hitchhiker.dat" ]] && ! [[ "$HITCHHIKER_DIR/hitchhiker.dat" -ot "$HITCHHIKER_DIR/hitchhiker" ]]; then
+    return
+  fi
+
+  # If strfile is not found: some systems install strfile in /usr/sbin but it's not in $PATH
+  if ! command -v strfile &>/dev/null && ! [[ -f /usr/sbin/strfile ]]; then
+    echo "[oh-my-zsh] hitchhiker 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
+
+  "${commands[strfile]:-/usr/sbin/strfile}" "$HITCHHIKER_DIR/hitchhiker" "$HITCHHIKER_DIR/hitchhiker.dat" >/dev/null
+}
+
+unset HITCHHIKER_DIR