DEAR PEOPLE FROM THE FUTURE: Here's what we've figured out so far...

Welcome! This is a Q&A website for computer programmers and users alike, focused on helping fellow programmers and users. Read more

What are you stuck on? Ask a question and hopefully somebody will be able to help you out!
+1 vote

I currently use the following in my initial shell prompt because I like the combination, but I think I've seen them all. I have all the others typically available, but many of them are offensive so when in the office, I can't really risk having it on my screen.


    fortune literature | \
        cowsay -f $(ls /usr/share/cowsay/cows/ | shuf -n1)



In Debian at least, the fortune package only contains a couple of lists. Do you already have the others from the fortunes package installed? It contains 1000s more.

1 Answer

+1 vote

For reasonably unlimited fun, you can get a random quote from Wikiquote via the Mediawiki API (or a scraper) and show that. This is my scraping attempt in a Ruby one-liner, CC0 licensed, open-uri and Nokogiri gems required:

ruby -r open-uri -r nokogiri -e 'html ="").read; doc = Nokogiri::HTML html; author = doc.title.split("- Wikiquote").first; print doc.css("li:not(:has(> li))").reject {|e| e.text.start_with? /\d/}.first.text; puts "\n~ #{author}"'

Does not work perfectly, it's a proof of concept but kinda works. Cherry-picked a cool quote it gave me:

The highest morality may prove also to be the highest wisdom when the
half-told story comes to be finished.

The Boer War (1902)

~ Arthur Conan Doyle


If I understand this, redirects the request to a random page at and then you extract a <li> randomly from the page?
Building on this answer: It would be possible to loop this oneliner thousands of times and collect all the returned quotes into a fortune file (but I guess they will not be categorized).


Yes, it extracts a <li> randomly with a filter that tries to avoid quote headers. It can be used to download as many quotes as you want (as long as you are respectful of Wikipedia's bandwidth, of course!).

I had a lot of fun writing it but I did some searching and there are ready solutions like wikiquote-fortune and there is a Python library for doing this. Here is a working example using that library for doing the same thing as the Ruby program above.

python3 -c 'import wikiquote as wq, random; author = wq.random_titles(max_titles=1)[0]; print(random.choice(wq.quotes(author))); print(f"~ {author}")'

Contributions licensed under CC0