How can I create a fortunes file and add it to the fortune
* command on the shell?
*Fortune - "console command to print a random, hopefully interesting, adage."
How can I create a fortunes file and add it to the fortune
* command on the shell?
*Fortune - "console command to print a random, hopefully interesting, adage."
To get you own custom fortune cookies first create a file and add the texts hat you want to be shown as a fortune.
In your text editor paste the text (string) you want to be show and between each string to be displayed there has to be a
%
assuming we are creating a quotes fortune,with filename
quotes
paste in your text and edit like this
save the file and create a dat file:
This creates a .dat file for your cookie file, which contains a header structure and a table of file offsets for each group of lines. This allows random access of the strings.
to see your fortune, do:
To make your cookies appear as a standard fortune cookie when you simply type fortune, add quotes and quotes.dat to /usr/share/games/fortunes/
If you want to add or subtract any string from your custom fortune cookie file,you will need to to run the
strfile -c % quotes quotes.dat
to create a new dat file againYou can also add your fortunes to bash such that when you open the shell you are greated by your custom fortune.
do
nano ~/.bashrc
and addfortune /path/to/quote | lolcat
to the end of the file and saveNow close your terminal and open a new terminal to see it work
This is explained in the manpages for
fortune(6)
and (especially)strfile(1)
.Basically, you create a text file that contains your "fortune cookies" separated by a line that contains a single
%
sign and nothing else. Each fortune cookie can be 1 or more lines (including empty lines). A random example from one of the default fortune cookie files:Then you use the
strfile
utility to create a binary search index (see its manpage for extra options). When you put both the text file and the binary index file in/usr/share/games/fortunes/
, your new fortune cookies should be available.The fortune command is documented here:
man fortune
. The man page tells you how to specify your own fortunes file. The default files live in /usr/share/games/fortunes (I found them by typinglocate fortune
.If you want to permanently add your custom file, there are several ways: put it in /usr/share/games/fortunes, make an alias (
help alias
) to fortune, etc.