diff options
Diffstat (limited to 'bash/bash_profile.d/verse.bash')
-rw-r--r-- | bash/bash_profile.d/verse.bash | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/bash/bash_profile.d/verse.bash b/bash/bash_profile.d/verse.bash index 428197dd..d7877a05 100644 --- a/bash/bash_profile.d/verse.bash +++ b/bash/bash_profile.d/verse.bash @@ -1,16 +1,21 @@ -# Run verse(1) if it's installed and we haven't seen it already today (the -# verses are selected by date); run in a subshell to keep vars out of global -# namespace -if [[ $- == *i* ]] && hash verse 2>/dev/null ; then ( +# Only if shell is interactive +[[ $- == *i* ]] || return + +# Only if verse(1) available +hash fortune 2>/dev/null || return + +# Run verse(1) if we haven't seen it already today (the verses are selected by +# date); run in a subshell to keep vars out of global namespace +( date=$(date +%Y-%m-%d) versefile=${VERSEFILE:-$HOME/.verse} - if [[ -e $HOME/.verse ]] ; then - read -r lastversedate < "$versefile" + if [[ -e $versefile ]] ; then + IFS= read -r lastversedate < "$versefile" fi if [[ $date > $lastversedate ]] ; then verse printf '\n' printf '%s\n' "$date" > "$versefile" fi -) ; fi +) |