aboutsummaryrefslogtreecommitdiff
path: root/bash
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2015-12-15 16:01:07 +1300
committerTom Ryder <tom@sanctum.geek.nz>2015-12-15 16:01:07 +1300
commit7b1b82761bcab157de124def3944dd95b19268b6 (patch)
tree1a181ac352e5963922c3a777322d9916d976950f /bash
parentRemove unneeded args spec (diff)
downloaddotfiles-7b1b82761bcab157de124def3944dd95b19268b6.tar.gz
dotfiles-7b1b82761bcab157de124def3944dd95b19268b6.zip
Flatten bash_profile.d subscripts a bit
Diffstat (limited to 'bash')
-rw-r--r--bash/bash_profile.d/fortune.bash12
-rw-r--r--bash/bash_profile.d/remind.bash19
-rw-r--r--bash/bash_profile.d/verse.bash19
3 files changed, 34 insertions, 16 deletions
diff --git a/bash/bash_profile.d/fortune.bash b/bash/bash_profile.d/fortune.bash
index f3ef2be9..9879716a 100644
--- a/bash/bash_profile.d/fortune.bash
+++ b/bash/bash_profile.d/fortune.bash
@@ -1,10 +1,16 @@
-# If interactive shell and fortune(6) installed, print a short fortune
-if [[ $- == *i* ]] && hash fortune 2>/dev/null ; then (
+# Only if shell is interactive
+[[ $- == *i* ]] || return
+
+# Only if fortune(6) available
+hash fortune 2>/dev/null || return
+
+# Print from subshell to keep namespace clean
+(
if [[ -d $HOME/.local/share/games/fortunes ]] ; then
FORTUNE_PATH=${FORTUNE_PATH:-$HOME/.local/share/games/fortunes}
fi
printf '\n'
fortune -sn "${FORTUNE_MAXSIZE:-768}" "$FORTUNE_PATH"
printf '\n'
-) ; fi
+)
diff --git a/bash/bash_profile.d/remind.bash b/bash/bash_profile.d/remind.bash
index 3f9908a0..d006bb20 100644
--- a/bash/bash_profile.d/remind.bash
+++ b/bash/bash_profile.d/remind.bash
@@ -1,10 +1,17 @@
-# If interactive, ~/.reminders, and rem(1), run it
-if [[ $- == *i* ]] && \
- [[ -e $HOME/.reminders ]] && \
- hash rem 2>/dev/null ; then (
- while read -r reminder ; do
+# Only if shell is interactive
+[[ $- == *i* ]] || return
+
+# Only if rem(1) available
+hash rem 2>/dev/null || return
+
+# Only if $HOME/.reminders exists
+[[ -e $HOME/.reminders ]] || return
+
+# Print from subshell to keep namespace clean
+(
+ while IFS= read -r reminder ; do
printf '* %s\n' "$reminder"
done < <(rem -hq)
printf '\n'
-) ; fi
+)
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
+)