Skip to content

Instantly share code, notes, and snippets.

@devashishp
Last active July 13, 2018 00:02
Show Gist options
  • Save devashishp/9e38d1af546f288ec80f375d4301e060 to your computer and use it in GitHub Desktop.
Save devashishp/9e38d1af546f288ec80f375d4301e060 to your computer and use it in GitHub Desktop.
Quickly create fortune databases out of your favorite (out-of-copyright) books and texts!

Fortune is a unix utility

  1. Download the plain-text of your favorite book :
  2. Name the file what you want the fortune command to invoke
    • eg alice
  3. Change line endings from DOS to unix :
    • :set ff=unix in vim
  4. Delete the preamble and license at the end
    • (while respecting it)
  5. Delete all the chapter titles
    • :g/CHAPTER*/d in vim
  6. Fix newline discrepancy
    • :%s/\n\n\n/\r\r/g with increasing number of \ns until nothing matches (let me know if there's a better way)
  7. Add % signs to separate paragraphs
    • :%s/\n\n/\r\r%\r\r/g
    • This could also be used to add author names/ book titles to each quote
  8. Randomize access to the file using strfile
    • strfile alice this should give you alice.dat
  9. Copy the fortunes to the right spot!
    • cp alice* /usr/share/games/fortune on FreeBSD
  10. Enjoy!
    • $fortune alice
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment