-
Notifications
You must be signed in to change notification settings - Fork 0
/
haiku
executable file
·42 lines (37 loc) · 1.17 KB
/
haiku
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
word_and_syllables () {
# Scrape dictionary.com to get the number of syllables in the word
# They don't have everything in /usr/share/dict/words, so loop until we find something
# that has some syllables
while true; do
WORD=`cat /usr/share/dict/words | grep -E "$1" | gshuf | head -n 1`;
SYLLABLES=`curl -G http://www.dictionary.com/browse/$WORD 2>/dev/null | grep 'data-syllable' | grep -E "$WORD[,<]" | head -n 1 | sed 's/[^·]//g' | wc -m`;
if [ $SYLLABLES -ne '0' ]; then
break
fi
done
}
for i in 5 7 5; do
while true; do
# Get a new word and syllables
word_and_syllables $1
# Use this word if it's not too big
if [ $SYLLABLES -le $i ]; then
echo -n "$WORD";
else
continue
fi
# Have we finished this line
(( i -= $SYLLABLES ))
if [ $i -eq 0 ]; then
echo "."
break
else
# Add some punctuation so make stuff dramatic
if [ $(($RANDOM % 5)) -eq '0' ]; then
echo -n ','
fi
echo -n ' '
fi
done
done