Create fortune data file

fortune is a utility for displaying random text items from a database. The data files for fortune is kept in the directory /usr/share/games/fortune by default. We can add our own data files to it.Suppose you want to display a random quote of Einstein whenever you type fortune einstein , as shown below.

hash@ssl51:~$ fortune einstein
"The eternal mystery of the world is its comprehensibility."

For that you have to create a data file with quotes from Einstein, and a 'dat' file for getting a random item from the quotes. The procedure is as follows.

  1. Create a file containing the quotes (items to be displayed) such that each quote is seperated by '%' symbol.


  2. "Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction."
    %
    "Imagination is more important than knowledge."
    %
    "Gravitation is not responsible for people falling in love."
    %
    "I want to know God's thoughts; the rest are details."
    %
    "The hardest thing in the world to understand is the income tax."
    %
    "Reality is merely an illusion, albeit a very persistent one."
    %
    "The only real valuable thing is intuition."
    %
    "A person starts to live when he can live outside himself."
    %
    "I am convinced that He (God) does not play dice."
    %
    "God is subtle but he is not malicious."
    %
    "Weakness of attitude becomes weakness of character."
    %
    "I never think of the future. It comes soon enough."
    %
    "The eternal mystery of the world is its comprehensibility."
    %
    "Sometimes one pays most for the things one gets for nothing."


  3. Now you have to create a 'dat' file for obtaining random item. For that you can use a tool strfile. If you have fortune-mod installed then the tool will be available. Suppose the file created in lasst step is named einstein. To create the datafile, just type as follows

    hash@ssl51:~$ strfile einstein
    "einstein.dat" created
    There were 14 strings
    Longest string: 168 bytes
    Shortest string: 41 bytes


  4. Now move both files to /usr/share/games/fortune

    hash@ssl51:~$ sudo mv einstein /usr/share/games/fortunes/
    [sudo] password for hash:
    hash@ssl51:~$ sudo mv einstein.dat /usr/share/games/fortunes/



It's done. Just type fortune einstein and see the result

hash@ssl51:~$ fortune einstein
"Imagination is more important than knowledge."
For more fun with displaying the text, check http://tech-hanoosh.blogspot.com/2009/05/cowsay-dialogues-by-cow-in-terminal.html

0 comments: