From 7b1b82761bcab157de124def3944dd95b19268b6 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 15 Dec 2015 16:01:07 +1300 Subject: Flatten bash_profile.d subscripts a bit --- bash/bash_profile.d/verse.bash | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'bash/bash_profile.d/verse.bash') 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 +) -- cgit v1.2.3