aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-09-01 13:56:42 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-09-01 13:56:42 +1200
commit0dc1c3460dc4c86ec1bfe8ab273775525e851fe5 (patch)
treece0577fb5ed9d3bdcb3b082ad6003a8323a275c9
parentUse terser syntax for path addition (diff)
downloaddotfiles-0dc1c3460dc4c86ec1bfe8ab273775525e851fe5.tar.gz
dotfiles-0dc1c3460dc4c86ec1bfe8ab273775525e851fe5.zip
Refactor welcome.sh
-rw-r--r--sh/profile.d/welcome.sh67
1 files changed, 29 insertions, 38 deletions
diff --git a/sh/profile.d/welcome.sh b/sh/profile.d/welcome.sh
index 26bf678f..ede7a05f 100644
--- a/sh/profile.d/welcome.sh
+++ b/sh/profile.d/welcome.sh
@@ -10,45 +10,36 @@ esac
# Not if ~/.hushlogin exists
[ -e "$HOME"/.hushlogin ] && return
+# Run all of this in a subshell to clear it away afterwards
(
- # Only if ~/.welcome/fortune exists
- [ -e "$HOME"/.welcome/fortune ] || exit
-
- # Only if fortune(6) available
- command -v fortune >/dev/null 2>&1 || exit
+ # Temporary helper function
+ welcome() {
+ [ -e "$HOME"/.welcome/"$1" ] || return
+ command -v "$1" >/dev/null 2>&1 || return
+ }
# Show a fortune
- [ -d "$HOME"/.local/share/games/fortunes ] &&
- : "${FORTUNE_PATH:="$HOME"/.local/share/games/fortunes}"
- fortune -s "$FORTUNE_PATH"
- printf '\n'
-)
-(
- # Only if ~/.welcome/remind exists
- [ -e "$HOME"/.welcome/remind ] || exit
-
- # Only if rem(1) available
- command -v rem >/dev/null 2>&1 || exit
-
- # Print reminders with asterisks
- rem -hq | sed 's/^/* /'
- printf '\n'
-)
-(
- # Only if ~/.welcome/remind verse
- [ -e "$HOME"/.welcome/verse ] || exit
-
- # Only if verse(1) available
- command -v verse >/dev/null 2>&1 || exit
-
- # 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
- now=$(date +%Y%m%d)
- last=0
- [ -f "$HOME"/.verse ] &&
- last=$(cat -- "$HOME"/.verse)
- [ "$now" -gt "$last" ] || exit
- verse
- printf '\n'
- printf '%s\n' "$now" > "$HOME"/.verse
+ if welcome fortune ; then
+ [ -d "$HOME"/.local/share/games/fortunes ] &&
+ : "${FORTUNE_PATH:="$HOME"/.local/share/games/fortunes}"
+ fortune -s "$FORTUNE_PATH"
+ printf '\n'
+ fi
+
+ # Print today's reminders with asterisks
+ if welcome rem ; then
+ rem -hq | sed 's/^/* /'
+ printf '\n'
+ fi
+
+ # Run verse(1) if we haven't seen it already today
+ if welcome verse ; then
+ [ -f "$HOME"/.verse ] && read -r last <"$HOME"/.verse
+ now=$(date +%Y%m%d)
+ if [ "$now" -gt "${last:-0}" ] ; then
+ verse
+ printf '\n'
+ printf '%s\n' "$now" >"$HOME"/.verse
+ fi
+ fi
)