• Linux
  • May 2019
    M T W T F S S
    « Apr    
     12345
    6789101112
    13141516171819
    20212223242526
    2728293031  
  • Meta

  • Follow me on Twitter

  • Advertisements

My Mint-Fortune

The fortune and cowsay programs are kind of fun and in many Linux distributions you can have them launch when you open a terminal.

Mint 18.3 and 19.1 with the Cinnamon desktop environment both have an if statement in ~/.bashrc that checks for the existence of mint-fortune and will run it if it exists in /usr/bin as an executable file. I’ve noticed that MX Linux 18 also has this statement although it’s based on Debian.

The mint-fortune script does exist in 18.3 and is executable but there’s a catch. There is a setting for a key in a gsettings schema that must be set to true which is set to false by default. Mint 19 doesn’t have this gsettings schema or key at all.

In Linux Mint 18.3 MATE there’s a checkbox in Desktop Settings that sets the key to true. If you’re on Linux Mint 18.x Cinnamon (this may also work for 17.x or earlier), you can enable it with the following commands:

# Check to see if the com.linuxmint.terminal is present
$ gsettings list-schemas | grep 'com.linuxmint.terminal'
com.linuxmint.terminal
# If present, check if the show-fortunes key is present
$ gsettings list-keys com.linuxmint.terminal | grep 'show-fortunes'
show-fortunes
# If present, check the value of show-fortunes
$ gsettings get com.linuxmint.terminal show-fortunes
false
# If show-fortunes is false, set to true
gsettings set com.linuxmint.terminal show-fortunes true
# Check the value of show-fortunes again
$ gsettings get com.linuxmint.terminal show-fortunes
true

Once the value is set to true, mint-fortune should run when you open a terminal provided fortune and cowsay are installed.

Linux Mint or other distributions running the XFCE desktop evironment will not have GSettings installed since it’s a Gnome feature. Linux Mint 19 Cinnamon doesn’t have either the GSettings schema or the mint-fortune script present.

I found a script in a Mint forum that has the same functionality as the packaged mint-fortune scipt and modified it a bit. All you need to do is place the script in /usr/bin and make sure it has execute privileges. You’ll need root (sudo) privileges to copy it.


#!/bin/bash

function show_fortune {
  RANGE=4
  number=$RANDOM
  let "number %= $RANGE"
  case $number in
  	0)
  		cow="default"
		;;
	1)
		cow="tux"
		;;
	2)
		cow="koala"
		;;
	3)
		cow="moose"
		;;
  esac

  RANGE=2
  number=$RANDOM
  let "number %= $RANGE"
  case $number in
	0)
		command="/usr/games/cowsay"
		;;
	1)
		command="/usr/games/cowthink"
		;;
  esac
  /usr/games/fortune | $command -f $cow
}

if [ -x "/usr/games/fortune" ] && [ -x "/usr/games/cowsay" ]; then
    show_fortune
fi

The script is nearly identical to the mint-fortune script that’s packaged with Mint 18.x and earlier but without the code that checks the value of the value of com.linuxmint.terminal show-fortunes.

I have written a script to install cowsay and fortune if they are not already installed. The script checks for the existence of /usr/bin/mint-fortune. If it exists, it checks for the GSetttings schema and the value of the show-fortunes key. If the script doesn’t exist it copies the script above into /usr/bin.

Advertisements
%d bloggers like this: