be3f96908e7f5e2278fb91ff3f72d1bb829f2698
- Author
- Marc Cornellà <marc.cornella@live.com>
- Committer
- Marc Cornellà <marc.cornella@live.com>
- Date
Message
Merge branch 'origin/refactor-rand-quote-plugin'
Diff
1diff --git a/plugins/rand-quote/README.md b/plugins/rand-quote/README.md
2new file mode 100644
3index 0000000000000000000000000000000000000000..c387aaa22456f1796afe168e7c580ef9c4d38737
4--- /dev/null
5+++ b/plugins/rand-quote/README.md
6@@ -0,0 +1,15 @@
7+# rand-quote plugin
8+
9+Displays a random quote taken from [quotationspage.com](http://www.quotationspage.com/random.php)
10+
11+Created by [Eduardo San Martin Morote, aka Posva](https://posva.github.io)
12+
13+## Usage
14+
15+Add the plugin to the plugins array in your zshrc file and restart zsh:
16+
17+```zsh
18+plugins=(... rand-quote)
19+```
20+
21+Then, run `quote` to get a new random quote.
22diff --git a/plugins/rand-quote/rand-quote.plugin.zsh b/plugins/rand-quote/rand-quote.plugin.zsh
23index 8f345d9aa1e04626c45195f07253ec2cccc5aba4..371b997d389ebca156b857d65d1e02b0fb9d1ea7 100644
24--- a/plugins/rand-quote/rand-quote.plugin.zsh
25+++ b/plugins/rand-quote/rand-quote.plugin.zsh
26@@ -1,26 +1,14 @@
27-# Get a random quote fron the site http://www.quotationspage.com/random.php3
28-# Created by Eduardo San Martin Morote aka Posva
29-# http://posva.github.io
30-# Sun Jun 09 10:59:36 CEST 2013
31-# Don't remove this header, thank you
32-# Usage: quote
33-
34-WHO_COLOR="\e[0;33m"
35-TEXT_COLOR="\e[0;35m"
36-COLON_COLOR="\e[0;35m"
37-END_COLOR="\e[m"
38-
39-if [[ -x `which curl` ]]; then
40- function quote()
41- {
42- 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 ")
43- TXT=$(echo "$Q" | sed -e 's/<\/dt>.*//g' -e 's/.*html//g' -e 's/^[^a-zA-Z]*//' -e 's/<\/a..*$//g')
44- W=$(echo "$Q" | sed -e 's/.*\/quotes\///g' -e 's/<.*//g' -e 's/.*">//g')
45- if [ "$W" -a "$TXT" ]; then
46- echo "${WHO_COLOR}${W}${COLON_COLOR}: ${TEXT_COLOR}“${TXT}”${END_COLOR}"
47- fi
48- }
49- #quote
50-else
51+if ! (( $+commands[curl] )); then
52 echo "rand-quote plugin needs curl to work" >&2
53+ return
54 fi
55+
56+function quote {
57+ emulate -L zsh
58+ 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 ")
59+
60+ TXT=$(echo "$Q" | sed -e 's/<\/dt>.*//g' -e 's/.*html//g' -e 's/^[^a-zA-Z]*//' -e 's/<\/a..*$//g')
61+ WHO=$(echo "$Q" | sed -e 's/.*\/quotes\///g' -e 's/<.*//g' -e 's/.*">//g')
62+
63+ [[ -n "$WHO" && -n "$TXT" ]] && print -P "%F{3}${WHO}%f: “%F{5}${TXT}%f”"
64+}