diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-09-01 13:56:42 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-09-01 13:56:42 +1200 |
commit | 0dc1c3460dc4c86ec1bfe8ab273775525e851fe5 (patch) | |
tree | ce0577fb5ed9d3bdcb3b082ad6003a8323a275c9 /sh/profile.d | |
parent | Use terser syntax for path addition (diff) | |
download | dotfiles-0dc1c3460dc4c86ec1bfe8ab273775525e851fe5.tar.gz dotfiles-0dc1c3460dc4c86ec1bfe8ab273775525e851fe5.zip |
Refactor welcome.sh
Diffstat (limited to 'sh/profile.d')
-rw-r--r-- | sh/profile.d/welcome.sh | 67 |
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 ) |