aboutsummaryrefslogtreecommitdiff
path: root/sh/profile.d/verse.sh
blob: ef68bb9399a3ec93f8d7e2ad7252daf067f14d89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Only if shell is interactive
case $- in
    *i*) ;;
    *) return ;;
esac

# Only if not in a tmux window on this machine
[ -z "$TMUX" ] || return

# Only if ~/.welcome/verse exists and ~/.hushlogin doesn't
[ -e "$HOME"/.welcome/verse ] || return
! [ -e "$HOME"/.hushlogin ] || return

# Only if verse(1) available
command -v verse >/dev/null 2>&1 || 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
(
    now=$(date +%Y-%m-%d)
    [ -f "$HOME"/.verse ] && last=$(cat -- "$HOME"/.verse)
    [ "$now" \> "$last" ] || exit
    verse
    printf '\n'
    printf '%s\n' "$now" > "$HOME"/.verse
)