chucknorris.plugin.zsh 862 B

12345678910111213141516171819202122232425
  1. () {
  2. # %x: name of file containing code being executed
  3. local fortunes_dir="${${(%):-%x}:h}/fortunes"
  4. # Aliases
  5. alias chuck="fortune -a $fortunes_dir"
  6. alias chuck_cow="chuck | cowthink"
  7. # Automatically generate or update Chuck's compiled fortune data file
  8. if [[ "$fortunes_dir/chucknorris" -ot "$fortunes_dir/chucknorris.dat" ]]; then
  9. return
  10. fi
  11. # For some reason, Cygwin puts strfile in /usr/sbin, which is not on the path by default
  12. local strfile="${commands[strfile]:-/usr/sbin/strfile}"
  13. if [[ ! -x "$strfile" ]]; then
  14. echo "[oh-my-zsh] chucknorris depends on strfile, which is not installed" >&2
  15. echo "[oh-my-zsh] strfile is often provided as part of the 'fortune' package" >&2
  16. return
  17. fi
  18. # Generate the compiled fortune data file
  19. $strfile "$fortunes_dir/chucknorris" "$fortunes_dir/chucknorris.dat" >/dev/null
  20. }