Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to get a fortune greeting in every terminal session

📅 2013-Aug-14 ⬩ ✍️ Ashwin Nanjappa ⬩ 📚 Archive

Cowsay-Fortune greeting
Cowsay-Fortune greeting

This is probably the oldest trick in Unix: getting a fun greeting every time you open a new terminal session. The typical way to do this to call fortune. If you pipe it to the ASCII cow and other animal characters available in cowsay, it becomes really cool.

One way to do this is to add this to your ~/.bashrc:

RANGE=2
number=$RANDOM
let "number %= $RANGE"

case $number in
    0)
        cowcommand="cowsay"
        ;;
    1)
        cowcommand="cowthink"
        ;;
esac

$cowcommand -f $(ls /usr/share/cowsay/cows/ | shuf -n1) $(fortune -s)

For Fish shell, add this to the end of your ~/.config/fish/config.fish:

fortune | cowsay -f (ls /usr/share/cowsay/cows/ | shuf -n1)

Tried with: Ubuntu 20.04