chucknorris.plugin.zsh 976 B

12345678910111213141516171819202122232425262728
  1. # chucknorris: Chuck Norris fortunes
  2. # Automatically generate or update Chuck's compiled fortune data file
  3. # $0 must be used outside a local function. This variable name is unlikly to collide.
  4. CHUCKNORRIS_PLUGIN_DIR=${0:h}
  5. () {
  6. local DIR=$CHUCKNORRIS_PLUGIN_DIR/fortunes
  7. if [[ ! -f $DIR/chucknorris.dat ]] || [[ $DIR/chucknorris.dat -ot $DIR/chucknorris ]]; then
  8. # For some reason, Cygwin puts strfile in /usr/sbin, which is not on the path by default
  9. local strfile=strfile
  10. if ! which strfile &>/dev/null && [[ -f /usr/sbin/strfile ]]; then
  11. strfile=/usr/sbin/strfile
  12. fi
  13. if which $strfile &> /dev/null; then
  14. $strfile $DIR/chucknorris $DIR/chucknorris.dat >/dev/null
  15. else
  16. echo "[oh-my-zsh] chucknorris depends on strfile, which is not installed" >&2
  17. echo "[oh-my-zsh] strfile is often provided as part of the 'fortune' package" >&2
  18. fi
  19. fi
  20. # Aliases
  21. alias chuck="fortune -a $DIR"
  22. alias chuck_cow="chuck | cowthink"
  23. }
  24. unset CHUCKNORRIS_PLUGIN_DIR