Random zen koans in your terminal
![zenHax zenHax](../../images/zenHax.jpg)
This is a small bash script to get a random zen koan in your terminal, I use this in my daily morning email thingy.
The koans are kindly provided by James Collado's ZenKoansDatabase. Don't abuse this site please.
I dump the contents of www.cincinato.org/koans/randomkoan_en.php using w3m and then do some simple manipulations of the output using sed. The title of the koan is outputted using FIGlet, the titles can sometimes be quite lengthy so it's advisable to use a small font for this. This script could be "simplified" to a one-liner but I find it notoriously hard to remember how to use sed so it makes sense for me to keep it super simple and readable.
#!/usr/bin/bash url="http://www.cincinato.org/koans/randomkoan_en.php" w3m -dump $url > /tmp/koan #delete 2 first lines sed -i 1,2d /tmp/koan #del 1st "[Another random English Koan]" sed -i '0,/\[Another random English Koan\]/s///' /tmp/koan #del * post last "[Another random English Koan]" sed -i '/\[Another random English Koan\]/,$d' /tmp/koan #get title of koan title=$(cat /tmp/koan | head -1) #del 1st line (title) sed -i '3d' /tmp/koan sed -i '1d;$d' /tmp/koan #remove blank lines from begin and end sed -i -e '/./,$!d' -e :a -e '/^\n*$/{$d;N;ba' -e '}' /tmp/koan figlet -f "mini" " $title :" cat /tmp/koan
An example:
_ _ / _.||o._ _ / _..__| o \_(_||||| |(_| \_(_||(_| o _| Keichu, the great Zen teacher of the Meiji era, was the head of Tofuku, a cathedral in Kyoto. One day the governor of Kyoto called upon him for the first time. His attendant presented the card of the governor, which read: Kitagaki, Governor of Kyoto. "I have no business with such a fellow," said Keichu to his attendant. "Tell him to get out of here." The attendant carried the card back with apologies. "That was my error," said the governor, and with a pencil he scratched out the words Governor of Kyoto. "Ask your teacher again." "Oh, is that Kitagaki?" exclaimed the teacher when he saw the card. "I want to see that fellow."