my xfce4 dotfiles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
699 B

3 years ago
  1. if ! (( $+commands[curl] )); then
  2. echo "rand-quote plugin needs curl to work" >&2
  3. return
  4. fi
  5. function quote {
  6. setopt localoptions nopromptsubst
  7. # Get random quote data
  8. local data
  9. data="$(command curl -s --connect-timeout 2 "http://www.quotationspage.com/random.php" \
  10. | iconv -c -f ISO-8859-1 -t UTF-8 \
  11. | command grep -a -m 1 'dt class="quote"')"
  12. # Exit if could not fetch random quote
  13. [[ -n "$data" ]] || return 0
  14. local quote author
  15. quote=$(sed -e 's|</dt>.*||g' -e 's|.*html||g' -e 's|^[^a-zA-Z]*||' -e 's|</a..*$||g' <<< "$data")
  16. author=$(sed -e 's|.*/quotes/||g' -e 's|<.*||g' -e 's|.*">||g' <<< "$data")
  17. print -P "%F{3}${author}%f: “%F{5}${quote}%f”"
  18. }