Last active
January 27, 2019 14:37
-
-
Save drench/95eecafea8bb945f475692c5fa9ede66 to your computer and use it in GitHub Desktop.
Neo-Yow!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
yow_url=https://raw.githubusercontent.com/shlomif/fortune-mod/eeea80856c35f1e4487eed3e59829539eb12c07b/fortune-mod/datfiles/zippy | |
all_yows() { | |
test -e './yow.dat' || curl --silent $yow_url | sed -E 's#(.)%#\1\\%#g' > yow.dat | |
cat yow.dat | |
} | |
total_yow_count() { | |
all_yows | grep '^%$' | wc -l | |
} | |
yow_index=$(( ( RANDOM % $(total_yow_count) ) )) | |
all_yows | while read -d% yow; do | |
if [ $yow_index -eq 0 ]; then | |
echo $yow | |
break | |
else | |
(( yow_index-- )) | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Demo: