How To: Customizing Fortunes

Write tutorials and howtos in here
There are more tutorials here http://community.linuxmint.com/tutorial/welcome
Forum rules
Do not start a support topic here please. Before you post please read this

How To: Customizing Fortunes

Postby green_is_good on Tue Jan 25, 2011 10:03 am

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%2527nhead+Wilson%2527s+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
Content format of original file
Screenshot-vasfort [Read-Only] (-usr-share-games-fortunes) - gedit.png (36.62 KiB) Viewed 1805 times
Attachments
Screenshot-Terminal.png
Custom fortune being displayed
Screenshot-Terminal.png (23.58 KiB) Viewed 1805 times
Last edited by green_is_good on Tue Feb 01, 2011 12:01 am, edited 4 times in total.
Real Devolution of Power. That's Linux!
User avatar
green_is_good
Level 1
Level 1
 
Posts: 11
Joined: Fri Sep 24, 2010 3:17 am
Location: Kerala, India

Linux Mint is funded by ads and donations.
 

Re: How To: Customizing Fortunes

Postby dagon on Sat Jan 29, 2011 12:08 pm

Image
Image
User avatar
dagon
Level 7
Level 7
 
Posts: 1690
Joined: Mon Dec 06, 2010 4:33 am
Location: Kungälv, Sweden

Re: How To: Customizing Fortunes

Postby green_is_good on Mon Jan 31, 2011 6:18 am

Details about strfile and unstr have been appended to the tutorial. Hope it suffices!
Real Devolution of Power. That's Linux!
User avatar
green_is_good
Level 1
Level 1
 
Posts: 11
Joined: Fri Sep 24, 2010 3:17 am
Location: Kerala, India

Re: How To: Customizing Fortunes

Postby hinto on Mon Jan 31, 2011 11:01 am

What brought me to Debian was one-stop shopping.
What brought me to SID was apt-get update && apt-get dist-upgrade.
User avatar
hinto
Level 6
Level 6
 
Posts: 1124
Joined: Thu Jul 09, 2009 7:32 pm
Location: Cary NC, USA

Re: How To: Customizing Fortunes

Postby Habitual on Mon Jan 31, 2011 11:07 am

Waaaaaaaay too much free time. :)

but a good walk-through.
What's a landing but a take off in reverse?
My DorkBlog
User avatar
Habitual
Level 7
Level 7
 
Posts: 1999
Joined: Sun Nov 21, 2010 8:31 pm
Location: Slackware

Re: How To: Customizing Fortunes

Postby green_is_good on Mon Jan 31, 2011 12:02 pm


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?
Real Devolution of Power. That's Linux!
User avatar
green_is_good
Level 1
Level 1
 
Posts: 11
Joined: Fri Sep 24, 2010 3:17 am
Location: Kerala, India

Re: How To: Customizing Fortunes

Postby green_is_good on Mon Jan 31, 2011 12:09 pm

Habitual wrote::)
but a good walk-through.

Thanks for your support!
Real Devolution of Power. That's Linux!
User avatar
green_is_good
Level 1
Level 1
 
Posts: 11
Joined: Fri Sep 24, 2010 3:17 am
Location: Kerala, India

Re: How To: Customizing Fortunes

Postby hinto on Mon Jan 31, 2011 1:06 pm

Sure...
They are from Mark Twain's Pudd'nhead Wilson. I think they are all open source.
-H
What brought me to Debian was one-stop shopping.
What brought me to SID was apt-get update && apt-get dist-upgrade.
User avatar
hinto
Level 6
Level 6
 
Posts: 1124
Joined: Thu Jul 09, 2009 7:32 pm
Location: Cary NC, USA

Re: How To: Customizing Fortunes

Postby TheShadowFog on Sun Oct 30, 2011 3:02 pm

Woah. This is a bloody awesome tutorial! Thannnk you!
User avatar
TheShadowFog
Level 1
Level 1
 
Posts: 12
Joined: Sun Oct 30, 2011 2:39 pm

Re: How To: Customizing Fortunes

Postby green_is_good on Tue Nov 01, 2011 11:13 am

TheShadowFog wrote:Woah. This is a bloody awesome tutorial! Thannnk you!

You are welcome! :D
Real Devolution of Power. That's Linux!
User avatar
green_is_good
Level 1
Level 1
 
Posts: 11
Joined: Fri Sep 24, 2010 3:17 am
Location: Kerala, India

Linux Mint is funded by ads and donations.
 

Return to Tutorials / Howtos

Who is online

Users browsing this forum: LoudMouth and 7 guests