From 5f3774db3149e988641140264b185461b519d0fa Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 23 Jun 2020 22:39:29 +1200 Subject: Apply XDG basedirs to welcome.sh --- sh/profile.d/welcome.sh | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'sh') 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 ) -- cgit v1.2.3