rand-quote.plugin.zsh 537 B

1234567891011121314
  1. if ! (( $+commands[curl] )); then
  2. echo "rand-quote plugin needs curl to work" >&2
  3. return
  4. fi
  5. function quote {
  6. emulate -L zsh
  7. Q=$(curl -s --connect-timeout 2 "http://www.quotationspage.com/random.php" | iconv -c -f ISO-8859-1 -t UTF-8 | grep -m 1 "dt ")
  8. TXT=$(echo "$Q" | sed -e 's/<\/dt>.*//g' -e 's/.*html//g' -e 's/^[^a-zA-Z]*//' -e 's/<\/a..*$//g')
  9. WHO=$(echo "$Q" | sed -e 's/.*\/quotes\///g' -e 's/<.*//g' -e 's/.*">//g')
  10. [[ -n "$WHO" && -n "$TXT" ]] && print -P "%F{3}${WHO}%f: “%F{5}${TXT}%f”"
  11. }