aboutsummaryrefslogtreecommitdiff
path: root/sh/profile.d/verse.sh
blob: 781d68bc353c1d106f5a79c7e8b0f74b637398fc (plain) (blame)
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
27
28
# 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)
    if [ -f "$HOME"/.verse ] ; then
        last=$(cat -- "$HOME"/.verse)
    fi
    [ "$now" \> "$last" ] || exit
    verse
    printf '\n'
    printf '%s\n' "$now" > "$HOME"/.verse
)