rand-quote.plugin.zsh 945 B

12345678910111213141516171819202122232425262728
  1. # Get a random quote fron the site http://www.quotationspage.com/random.php3
  2. # Created by Eduardo San Martin Morote aka Posva
  3. # http://posva.github.io
  4. # Sun Jun 09 10:59:36 CEST 2013
  5. # Don't remove this header, thank you
  6. # Usage: quote
  7. WHO_COLOR="\e[0;33m"
  8. TEXT_COLOR="\e[0;35m"
  9. COLON_COLOR="\e[0;35m"
  10. END_COLOR="\e[m"
  11. if [[ -x `which curl` ]]; then
  12. function quote()
  13. {
  14. Q=$(curl -s --connect-timeout 2 "http://www.quotationspage.com/random.php3" | iconv -c -f ISO-8859-1 -t UTF-8 | grep -m 1 "dt ")
  15. TXT=$(echo "$Q" | sed -e 's/<\/dt>.*//g' -e 's/.*html//g' -e 's/^[^a-zA-Z]*//' -e 's/<\/a..*$//g')
  16. W=$(echo "$Q" | sed -e 's/.*\/quotes\///g' -e 's/<.*//g' -e 's/.*">//g')
  17. if [ "$W" -a "$TXT" ]; then
  18. echo "${WHO_COLOR}${W}${COLON_COLOR}: ${TEXT_COLOR}“${TXT}”${END_COLOR}"
  19. else
  20. quote
  21. fi
  22. }
  23. #quote
  24. else
  25. echo "rand-quote plugin needs curl to work" >&2
  26. fi