-
Notifications
You must be signed in to change notification settings - Fork 0
Rainbow Cow Fortune Teller
A fun script to be placed in .bashrc || .profile
which will tell you a fortune from a cow
in rainbow technicolors.
Install on Ubuntu/Debian or other Linux distros, MacOS, or Windows WSL distros
sudo apt install fortune cowsay lolcat -y
This script, once inserted in your .bashrc
or .profile
file in your home directory, will search
for a custom BASH function that I've written, and which can be found farther down on this page.
If it doesn't find the BASH function, it will search for a script variation ** (make sure to change
this to a location that exists on your machine) ** , if the shell script isn't located, it will
perform the scripted process itself. The order of checks and operations is:
NOTE: You can modify this however you like. I was just trying to make it failsafe on my own machine, so no matter what, it would run. The only thing I didn't do was have it install the applications itself, but that could easily be done, if desired.
Need to have this function file sourced with .bashrc or .profile using:
# add this to your bash .profile or .bashrc file and change filepath to match your location and filename
if [ -f "~/code/scripts/bash/my_bash_functions" ]; then
. "~/code/scripts/bash/my_bash_fucntion"
fi
# fortune told by rainbow cow
function rainbow_cow_fortune(){
# variables for app lookup
GAMES=/usr/games
set -- "fortune" "cowsay" "lolcat"
if [ -d "$GAMES" ]; then
# declare some variables
CHECK="true"
declare -a MISSING
# loop through app list
for g in $@; do
if [ -f "$GAMES/$g" ] && [ "$CHECK" == "true" ]; then
CHECK="true"
else
CHECK="false"
MISSING+=("$GAMES/$g")
fi
done
# execute if CHECK is good, otherwise report missing app
if [ $CHECK == "true" ]; then
fortune | cowsay | lolcat
else
echo "One or more apps aren't detected on your system!"
echo "Apps searched for: $@"
echo "Missing app: ${MISSING[0]}"
fi
fi
}
add this to your
.bashrc
or.profile
and change the directory paths accordingly.
if [ -n "$(LC_ALL=C type -t rainbow_cow_fortune)" ] && [ "$(LC_ALL=C type -t rainbow_cow_fortune)" == function ]; then
echo 'function'
rainbow_cow_fortune
elif [ -x ~/code/scripts/bash/rainbow-cow-fortune.sh ]; then
echo 'script:'
~/code/scripts/bash/rainbow-cow-fortune.sh
else
echo 'bashrc:'
GAMES=/usr/games
set -- "fortune" "cowsay" "lolcat"
if [ -d "$GAMES" ]; then
# declare some variables
CHECK="true"
declare -a MISSING=
# loop through app list
for g in $@; do
if [ -f "$GAMES/$g" ] && [ "$CHECK" == "true" ]; then
CHECK="true"
else
CHECK="false"
MISSING+=("$GAMES/$g")
fi
done
# execute if CHECK is good, otherwise report missing app
if [ $CHECK == "true" ]; then
fortune | cowsay | lolcat
else
echo "One or more apps aren't detected on your system!"
echo "Apps searched for: $@"
echo "Missing app: ${MISSING[0]}"
fi
fi
fi
Checkout my GitHub repo that has all of these and more BASH goodies.
If you'd like to make these better in some way, please feel free to create an issue on my repo, or fork my repo; update/mod the code, and submit a Pull Request on GitHub.com/devopsmyth/bash-mash.
Do NOT forget to USE-AT-YOUR-OWN-RISK with any scripts you find here or anywhere else online. I don't claim to have written any of the scripts on my repo entirely from scratch, I'm sure I borrowed ideas and snippets from lots of places. If you see something that resembles some other work, there's a possibility that I learned from that same resource. I am by no means an expert in Linux, or BASH, I'm just a hobbyist and IT professional with many years of experience. This is my first foray into sharing my personal stuff online, so keep the criticisms useful, please.
Contact Email: [email protected]