Skip to content

Commit

Permalink
Improve easter egg for 20 years of grml.org
Browse files Browse the repository at this point in the history
Relevant changes:

1) Don't convert dates via date(1), but provide epoch seconds right away
2) Also use zsh's ${EPOCHSECONDS} instead of forking to date(1)
3) Display easter egg message with einfo iff we are within the birthday range
4) Don't display easter egg only on 2023-09-16 and one month later,
   but also in all the days in between (sigh :))
5) Don't display anything at all when booting with noeasteregg boot option

Thanks: Christopher Bock and András Korn
  • Loading branch information
mika committed Sep 16, 2023
1 parent 2b0f0ee commit 46daec4
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions autoconfig.functions
Original file line number Diff line number Diff line change
Expand Up @@ -1994,17 +1994,24 @@ fi

# {{{ Easteregg (for 20 years grml.org)
config_easteregg() {
current_date=$(date +%Y-%m-%d)
birthday="2023-09-16"
one_month_later=$(date -d "${current_date} + 1 month" +%Y-%m-%d)
if checkbootparam 'noeasteregg'; then
return 0
fi

einfo "You found the birthday easter egg!" ; eend 0
local birthday current_date one_month_later
zmodload zsh/datetime

birthday='1694822400' # := 2023-09-16 -> TZ=UTC date -d "2023-09-16" +%s
one_month_later='1697407200' # := 2023-10-16 -> TC=UTC date -d "2023-09-16 + 1 month" +%s
current_date="${EPOCHSECONDS}" # simulate: current_date="$(date -d 2024-09-16 +%s)"

# nothing to be done if it's more than one month since $birthday
if ! [[ "${current_date}" == "${birthday}" || "${current_date}" == "${one_month_later}" ]]; then
# skip output before birthday or after one month has passend
if ! [[ "${current_date}" -ge "${birthday}" && "${current_date}" -lt "${one_month_later}" ]]; then
return 0
fi

einfo "You found the birthday easter egg!" ; eend 0

if [[ -x /bin/toilet && -x /usr/games/lolcat ]] ; then
visualize() { printf "%s\n" "$*" | toilet | /usr/games/lolcat ; }
elif [[ -x /bin/toilet ]] ; then
Expand All @@ -2017,6 +2024,7 @@ config_easteregg() {
visualize "20 years"
visualize "grml.org"
}

# }}}

## END OF FILE #################################################################
Expand Down

0 comments on commit 46daec4

Please sign in to comment.