hitchhiker.plugin.zsh 847 B

1234567891011121314151617181920212223
  1. HITCHHIKER_DIR="${0:h}/fortunes"
  2. # Aliases
  3. alias hitchhiker="fortune -a $HITCHHIKER_DIR"
  4. alias hitchhiker_cow="hitchhiker | cowthink"
  5. () {
  6. # Don't generate hitchhiker.dat if it exists and is up-to-date
  7. if [[ -f "$HITCHHIKER_DIR/hitchhiker.dat" ]] && ! [[ "$HITCHHIKER_DIR/hitchhiker.dat" -ot "$HITCHHIKER_DIR/hitchhiker" ]]; then
  8. return
  9. fi
  10. # If strfile is not found: some systems install strfile in /usr/sbin but it's not in $PATH
  11. if ! command -v strfile &>/dev/null && ! [[ -f /usr/sbin/strfile ]]; then
  12. echo "[oh-my-zsh] hitchhiker depends on strfile, which is not installed" >&2
  13. echo "[oh-my-zsh] strfile is often provided as part of the 'fortune' package" >&2
  14. return
  15. fi
  16. "${commands[strfile]:-/usr/sbin/strfile}" "$HITCHHIKER_DIR/hitchhiker" "$HITCHHIKER_DIR/hitchhiker.dat" >/dev/null
  17. }
  18. unset HITCHHIKER_DIR