-export COWPATH="/usr/local/git/cowfiles:/usr/local/git/cowsay-files/cows:/usr/local/share/localcows:/usr/local/share/cows"
-
+# ~/.bsah_lgout
function lolcatcowsayfortune {
# randomly pick between cowsay and cowthink
eye_type=${eye_types[ $RANDOM % 8 ]}
NUMOFCOWS=`cowsay -l | grep -v "Cow files in" | tail -n +2 | wc -w`
- WHICHCOW=$((RANDOM%$NUMOFCOWS+1))
+ WHICHCOW= $((RANDOM%$NUMOFCOWS+1))
THISCOW=`cowsay -l | tail -n +2 | sed -e 's/\ /\'$'\n/g' | sed $WHICHCOW'q;d'`
#echo "Selected cow: ${THISCOW}, from ${WHICHCOW}"
fortune -s | $cowsay_type $eye_type -f $THISCOW -n | lolcat
}
-# fortune, with cowsay and random cows, and lolcat; here instead of .bashrc
+# require all components to be installed for function to execute
+# fortune, with cowsay and random cows, and lolcat; here instead of .bashrc
# to prevent remote eommands from failing due to output being generated
-if [ -e /usr/local/share/cows ] && [ -x /usr/local/bin/cowsay ] && [ -x /usr/local/bin/fortune ] && [ -x /usr/local/bin/lolcat ]; then
+if [ -n "$COWPATH" ] && [ -x "$(command -v cowsay)" ] && [ -x "$(command -v fortune)" ] && [ -x "$(command -v lolcat)" ]; then
lolcatcowsayfortune
+else
+ echo "Missing required components, please check to ensure that fortune, cowsay, and lolcat are all installed, and that COWPATH is not null."
fi
[[ -s ~/.bashrc ]] && source ~/.bashrc
-export COWPATH="/usr/local/git/cowfiles:/usr/local/git/cowsay-files/cows:/usr/local/share/localcows:/usr/local/share/cows"
+# dynamically build COWPATH based on commonly used locations for cowfiles
+if [ -e /usr/local/git/cowfiles ]; then
+ COWPATH="/usr/local/git/cowfiles:$COWPATH"
+fi
+if [ -e /usr/local/git/cowsay-files/cows ]; then
+ COWPATH="/usr/local/git/cowsay-files/cows:$COWPATH"
+fi
+if [ -e /usr/local/share/localcows ]; then
+ COWPATH="/usr/local/share/localcows:$COWPATH"
+fi
+if [ -e /usr/local/share/cows ]; then
+ COWPATH="/usr/local/share/cows:$COWPATH"
+fi
+if [ -e /usr/share/cowsay ]; then
+ COWPATH="/usr/share/cowsay:$COWPATH"
+fi
+
+if [ -n "$COWPATH" ]; then
+ export COWPATH
+fi
function lolcatcowsayfortune {
eye_type=${eye_types[ $RANDOM % 8 ]}
NUMOFCOWS=`cowsay -l | grep -v "Cow files in" | tail -n +2 | wc -w`
- WHICHCOW=$((RANDOM%$NUMOFCOWS+1))
+ WHICHCOW= $((RANDOM%$NUMOFCOWS+1))
THISCOW=`cowsay -l | tail -n +2 | sed -e 's/\ /\'$'\n/g' | sed $WHICHCOW'q;d'`
#echo "Selected cow: ${THISCOW}, from ${WHICHCOW}"
fortune -s | $cowsay_type $eye_type -f $THISCOW -n | lolcat
}
-# fortune, with cowsay and random cows, and lolcat; here instead of .bashrc
+# require all components to be installed for function to execute
+# fortune, with cowsay and random cows, and lolcat; here instead of .bashrc
# to prevent remote eommands from failing due to output being generated
-if [ -e /usr/local/share/cows ] && [ -x /usr/local/bin/cowsay ] && [ -x /usr/local/bin/fortune ] && [ -x /usr/local/bin/lolcat ]; then
+if [ -n "$COWPATH" ] && [ -x "$(command -v cowsay)" ] && [ -x "$(command -v fortune)" ] && [ -x "$(command -v lolcat)" ]; then
lolcatcowsayfortune
+else
+ echo "Missing required components, please check to ensure that fortune, cowsay, and lolcat are all installed, and that COWPATH is not null."
fi