How To: Customizing Fortunes

Write tutorials for Linux Mint here
More tutorials on https://github.com/orgs/linuxmint/discu ... /tutorials and (archive) on https://community.linuxmint.com/tutorial
Forum rules
Don't add support questions to tutorials; start your own topic in the appropriate sub-forum instead. Before you post read forum rules
Post Reply
green_is_good

How To: Customizing Fortunes

Post by green_is_good »

Ever wanted the bubble above the "fortune-teller" animal to display something that you have created(with YOUR Name of course)? It's pretty simple to display your "words of wisdom" as fortunes each time you open the terminal or perform a console login.
1)First of all, create a file containing the fortunes that you want to display. Begin the contents of the file with a % sign. Then fill it with the phrases, expressions or sayings of your choice. Remember to separate each phrase using the % sign.
2)Generate a ".dat" file for the file that was created in step 1. This can be done by using the "strfile" command as shown below:

Code: Select all

strfile -r filename
Now a ".dat" file with the same name as the file created in step 1 will be generated.
3)Go to the directory "/usr/share/games/fortunes" (with administrator privileges!). This directory may vary and can be found out from fortune man page.
4)Simply copy and paste the files created in steps 1 and 2 into the directory in step 3.
5)Prevent sayings by Shakespeare or other people(no Offense!) from popping up by deleting their corresponding ".dat" files.(I strongly advice you to make a backup of these ".dat" files before getting rid of them!)

Close the directory and you are good to go! Show it off to your "Windows obsessed" friends. Let them know about the Flexibility that Linux offers!

Some really witty maxims from Mark Twain's Pudd'nhead Wilson are available at the following links(Courtesy hinto):
http://everything2.com/title/Pudd%2527n ... s+Calendar
http://etext.virginia.edu/railton/wilson/pwequat.html

ONLY for those who like to get to the bottom of things:
strfile command as described in its man-page "reads a file containing groups of lines separated by a line containing a single percent `%' sign (or other specified delimiter character) and creates a data file which contains a header structure and a table of file offsets for each group of lines." This header and offset table are used by the fortune program to display the fortunes contained in a particular file. When a particular entry in the offset table is added to the header value, it points to the corresponding fortune which then gets displayed. The "-r" option causes the entries in the offset table to be arranged randomly. This is because, even if the offset table entries were read in a sequential manner we will still get randomized fortunes.
unstr command takes the ".dat" data file as input and prints the contents of the original file (the one containing fortunes separated by '%' character) in the order in which the offset table entries were made.

Screenshot-vasfort [Read-Only] (-usr-share-games-fortunes) - gedit.png
Last edited by green_is_good on Tue Feb 01, 2011 12:01 am, edited 4 times in total.
dagon
Level 7
Level 7
Posts: 1655
Joined: Mon Dec 06, 2010 4:33 am
Location: Kungälv, Sweden
Contact:

Re: How To: Customizing Fortunes

Post by dagon »

Image
green_is_good

Re: How To: Customizing Fortunes

Post by green_is_good »

Details about strfile and unstr have been appended to the tutorial. Hope it suffices!
deleted

Re: How To: Customizing Fortunes

Post by deleted »

Habitual

Re: How To: Customizing Fortunes

Post by Habitual »

Waaaaaaaay too much free time. :)

but a good walk-through.
green_is_good

Re: How To: Customizing Fortunes

Post by green_is_good »

Thanks for the suggestion. I am pretty sure that the witty maxims from the calendar will be a hit among the users! Will it be okay if I include the links provided by you in the tutorial?
green_is_good

Re: How To: Customizing Fortunes

Post by green_is_good »

Habitual wrote::)
but a good walk-through.
Thanks for your support!
deleted

Re: How To: Customizing Fortunes

Post by deleted »

Sure...
They are from Mark Twain's Pudd'nhead Wilson. I think they are all open source.
-H
TheShadowFog

Re: How To: Customizing Fortunes

Post by TheShadowFog »

Woah. This is a bloody awesome tutorial! Thannnk you!
green_is_good

Re: How To: Customizing Fortunes

Post by green_is_good »

TheShadowFog wrote:Woah. This is a bloody awesome tutorial! Thannnk you!
You are welcome! :D
Post Reply

Return to “Tutorials”