Fortune

From ArchWiki
Jump to navigation Jump to search

fortune is a simple program that displays random poignant, inspirational, silly or snide phrase from a database of quotations. The fortune command-line utility is part of the fortune-mod package.

Installation

Install fortune-mod or fortune-mod-gitAUR.

Tip: Meta packages which provide quotes from specific sources are available in the AUR. For example, fortune-mod-archlinuxAUR contains Arch related quotes. You can use wikiquote-fortuneAUR to generate fortune files from wikiquote pages, using the syntax wikiquote-fortune X, where X is the page's name. To use these files, run $ fortune /path/to/quote.

Usage

  • Command-line in a terminal:
$ fortune
It is Texas law that when two trains meet each other at a railroad crossing,
each shall come to a full stop, and neither shall proceed until the other has gone.
  • To display a random quote when launching an interactive terminal, add the fortune command to the rc configuration file of your preferred shell:
#!/bin/bash
# ~/.bashrc
fortune
#!/bin/dash
# ~/.dashrc
fortune
  • To display a random quote when logging into a login terminal, add the fortune command to the profile configuration file of your preferred shell:
#!/bin/mksh
# ~/.profile
fortune
Note: fortune displays quotes and phrases deemed by its maintainer to be non-offensive. Aphorisms can be enabled as a mix of offensive/non-offensive or as potentially offensive output only. See fortune(6) for more information.

Creating custom files

In order to create a custom file, you must first create a file containing the quotes. Between each quote you must add a line containing only the % character. Save this file using whatever name you want, for example myquotes. Then, run strfile myquotes in a terminal, in order to enable random access of the quotes. You can now access the quotes by executing fortune myquotes in a terminal. For this command to work you must be on the same directory as the myquotes and myquotes.dat files. If you want your quotes to be accessible by just running the fortune command, you must move both files into the /usr/share/fortune/ directory. If you want to make any changes to your file, repeat from the start.

Cowsay

Merge-arrows-2.pngThis article or section is a candidate for merging with ASCII art.Merge-arrows-2.png

Notes: Better fits there. (Discuss in Talk:Fortune#merge)

Default cow with fortune

  • Combined with the program cowsay:
$ cowthink $(fortune)
 ________________________________________ 
( The best cure for insomnia is to get a )
( lot of sleep. -W.C. Fields             )
 ---------------------------------------- 
        o   ^__^
         o  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||
  • Display a potentially offensive fortune:
$ cowsay $(fortune -o)
 _________________________________ 
< Chastity is its own punishment. >
 --------------------------------- 
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

The ASCII images are generated by .cow text files located in /usr/share/cows, and all themes can be listed with the cowsay -l. These files can be edited to the user's liking; custom images can also be created from scratch or found on the net. The easiest way create a custom cow file is to use an existing one as a template. To test the custom file:

$ cowsay -f /path/to/file $(fortune)

Random cow with fortune

$ fortune -c | cowthink -f $(find /usr/share/cows -type f | shuf -n 1)
  ___________________________________________
( (computers) % A language that doesn't )
( affect the way you think about                  )
( programming is not worth knowing.       )
  ------------------------------------------------------
         o      (__)
          o     /oo|
           o   (_"_)*+++++++++*
                    //I#\ \ \ \ \ \ \ \   I \
                   I[I|I | | | | |   I I `
                   I`I ' /  /  /  '  '     I I
                   I I                       I I
                  ~ ~                     ~ ~
                        Scowleton

Random custom cow with fortune

Complex commands can be chained to produce detailed ASCII art sych as this Futurama example.

  • Display a random cow with a random facial expression and wrap long lines of fortune text:
Note: The randomly selected cow is actually a toad chosen from a database with custom ASCII art
$ fortune -a | fmt -80 -s | $(shuf -n 1 -e cowsay cowthink) -$(shuf -n 1 -e b d g p s t w y) -f $(shuf -n 1 -e $(cowsay -l | tail -n +2)) -n
    ________________________________________ 
( Fry: I must be a robot. Why else would )
( human women refuse to date me?         )
    -------------------------------------------------- 
      o
        o
          o  
             ,'``.._   ,'``.
            :,--._:)\,:,._,.:
            :`--,@@@:`...';\        
             `,'@@@@@@@`---'@@`.     
             /@@@@@@@@@@@@@@@@@:
            /@@@@@@@@@@@@@@@@@@@\
          ,'@@@@@@@@@@@@@@@@@@@@@:\.___,-.
         `...,---'``````-..._@@@@|:@@@@@@@\
           (                 )@@@;:@@@@)@@@\  _,-.
            `.              (@@@//@@@@@@@@@@`'@@@@\
             :               `.//@@)@@@@@@)@@@@@,@;
             |`.            _,'/@@@@@@@)@@@@)@,'@,'
             :`.`-..____..=:.-':@@@@@.@@@@@_,@@,'
            ,'\ ``--....-)='    `._,@@\    )@@@'``._
           /@_@`.       (@)      /@@@@@)  ; / \ \`-.'
          (@@@`-:`.     `' ___..'@@_,-'   |/   `.)
           `-. `.`.``-----``--,@@.'
             |/`.\`'        ,',');
                 `         (/  (/

Ponysay

Merge-arrows-2.pngThis article or section is a candidate for merging with ASCII art.Merge-arrows-2.png

Notes: Better fits there. (Discuss in Talk:Fortune#merge)

For full 256-colored cowsay-like art use ponysay (version 3.0 has 422 ponies). The syntax is the same, meaning $ ponysay message to say something and ponysay -l for a complete list of ponies. To select a pony to display, run $ ponysay --pony x "message", where x is a pony. To create more ponies use util-say-gitAUR and store them in ~/.local/share/ponysay/ponies and ~/.local/share/ponysay/ttyponies/ for desktop and TTY, respectively.

See also