Parent directory

rand-quote.plugin.zsh

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