diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2020-06-23 22:39:29 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2020-06-23 22:39:29 +1200 |
commit | 5f3774db3149e988641140264b185461b519d0fa (patch) | |
tree | 7ce1243d95c0ead0729c6315326d88e9dfd5ff8d /sh/profile.d/welcome.sh | |
parent | Use tabs in Mutt mailcap (diff) | |
download | dotfiles-5f3774db3149e988641140264b185461b519d0fa.tar.gz dotfiles-5f3774db3149e988641140264b185461b519d0fa.zip |
Apply XDG basedirs to welcome.sh
Diffstat (limited to 'sh/profile.d/welcome.sh')
-rw-r--r-- | sh/profile.d/welcome.sh | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/sh/profile.d/welcome.sh b/sh/profile.d/welcome.sh index 3cb420c5..d1a6b52d 100644 --- a/sh/profile.d/welcome.sh +++ b/sh/profile.d/welcome.sh @@ -14,15 +14,18 @@ esac ( # Temporary helper function welcome() { - [ -e "$HOME"/.config/welcome/"$1" ] || return + [ -e "${XDG_CONFIG_HOME:-"$HOME"/.config}"/welcome/"$1" ] || return command -v "$1" >/dev/null 2>&1 || return } # Show a fortune if welcome fortune ; then - if [ -z "$FORTUNE_PATH" ] && - [ -d "$HOME"/.local/share/games/fortunes ] ; then - FORTUNE_PATH=$HOME/.local/share/games/fortunes + if [ -z "$FORTUNE_PATH" ] ; then + FORTUNE_PATH=${XDG_DATA_HOME:-$HOME}/.local/share/fortune + set -- "$FORTUNE_PATH"/*.dat + if ! [ -e "$1" ] ; then + FORTUNE_PATH=all + fi fi fortune -s "$FORTUNE_PATH" printf '\n' @@ -36,14 +39,16 @@ esac # Run verse(1) if we haven't seen it already today if welcome verse ; then - if [ -f "$HOME"/.verse ] ; then - read -r last <"$HOME"/.verse + cache=${XDG_CACHE_HOME:-$HOME/.cache}/verse + mkdir -p -- "$cache" + if [ -f "$cache"/last ] ; then + read -r last <"$cache"/last fi now=$(date +%Y%m%d) if [ "$now" -gt "${last:-0}" ] ; then verse printf '\n' - printf '%s\n' "$now" >"$HOME"/.verse + printf '%s\n' "$now" >"$cache"/last fi fi ) |