# Display fortune (with cowsay if available) in top-level interactive shells # (new iTerm2 tabs/windows, xterm, console, VS Code / IntelliJ terminals). # Subshells (e.g. typing 'bash' or 'zsh' inside an existing terminal) are skipped. case $- in *i*) ;; *) return 0 2>/dev/null || exit 0 ;; esac # Skip nested subshells (SHLVL > 1) if [ "${SHLVL:-1}" -gt 1 ]; then return 0 2>/dev/null || exit 0 fi _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