diff --git a/.rc.d/fortune.sh b/.rc.d/fortune.sh index 476cd09..2c63284 100755 --- a/.rc.d/fortune.sh +++ b/.rc.d/fortune.sh @@ -1,7 +1,37 @@ -if [ -f "/opt/homebrew/bin/fortune" ]; then - if [ -f "/opt/homebrew/bin/cowsay" ]; then - /opt/homebrew/bin/fortune | /opt/homebrew/bin/cowsay - else - /opt/homebrew/bin/fortune - fi +# Display fortune (with cowsay if available) in interactive shells +case $- in + *i*) ;; + *) return 0 2>/dev/null || exit 0 ;; +esac + +_fortune_cmd="" +if command -v fortune >/dev/null 2>&1; then + _fortune_cmd="fortune" +elif [ -x "/opt/homebrew/bin/fortune" ]; then + _fortune_cmd="/opt/homebrew/bin/fortune" +elif [ -x "/usr/games/fortune" ]; then + _fortune_cmd="/usr/games/fortune" +elif [ -x "/usr/local/bin/fortune" ]; then + _fortune_cmd="/usr/local/bin/fortune" fi + +if [ -n "$_fortune_cmd" ]; then + _cowsay_cmd="" + if command -v cowsay >/dev/null 2>&1; then + _cowsay_cmd="cowsay" + elif [ -x "/opt/homebrew/bin/cowsay" ]; then + _cowsay_cmd="/opt/homebrew/bin/cowsay" + elif [ -x "/usr/games/cowsay" ]; then + _cowsay_cmd="/usr/games/cowsay" + elif [ -x "/usr/local/bin/cowsay" ]; then + _cowsay_cmd="/usr/local/bin/cowsay" + fi + + if [ -n "$_cowsay_cmd" ]; then + "$_fortune_cmd" | "$_cowsay_cmd" + else + "$_fortune_cmd" + fi + unset _cowsay_cmd +fi +unset _fortune_cmd