]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/rand-quote/rand-quote.plugin.zsh
initial
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / rand-quote / rand-quote.plugin.zsh
1 if ! (( $+commands[curl] )); then
2   echo "rand-quote plugin needs curl to work" >&2
3   return
4 fi
5
6 function quote {
7   setopt localoptions nopromptsubst
8
9   # Get random quote data
10   local data
11   data="$(command curl -s --connect-timeout 2 "http://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 }