]> git.armaanb.net Git - bin.git/blob - fortune
fortune: Wrap in shell script and remove grep call
[bin.git] / fortune
1 #!/usr/bin/sh -e
2 # Fortune implementation in awk
3
4 awk '$1 == "%" {
5   sub(/%/, "")
6   ++f
7 }
8
9 {
10   fortunes[f] = fortunes[f] (length(fortunes[f])?"\n":"") $0
11 }
12
13 END {
14   "date +%N" | getline time
15   srand(time)
16   print fortunes[int(rand() * f) + 1]
17 }' ${1:-"/usr/share/fortune/cookie"}