bash/bashrc.d/20-greeting.bash
2026-10-27 13:13:29 +00:00

75 lines
1.9 KiB
Bash

# shellcheck shell=bash
show_date() {
local dotfile selected_adjective adjective classification
local today day_of_week day_of_month month_name year day_suffix text_color full_date
local -a adjectives
dotfile="$HOME/.adjective_of_the_day"
today=$(date +%F)
if [[ -f "$dotfile" && $(date -r "$dotfile" +%F) == "$today" ]]; then
selected_adjective=$(cat "$dotfile")
else
adjectives=(
"beautiful:positive"
"engaging:positive"
"majestic:positive"
"distinguished:positive"
"venerable:positive"
"formal:positive"
"elegant:positive"
"serene:positive"
"graceful:positive"
"regal:positive"
"noble:positive"
"miserable:negative"
"worthless:negative"
"depressing:negative"
"soulless:negative"
"desolate:negative"
"archaic:negative"
"grim:negative"
"dreadful:negative"
"forlorn:negative"
"wretched:negative"
"neutral:neutral"
"ordinary:neutral"
"common:neutral"
"antique:neutral"
"ceremonial:neutral"
"timeless:neutral"
"classic:neutral"
"historic:neutral"
"ancient:neutral"
)
selected_adjective="${adjectives[$RANDOM % ${#adjectives[@]}]}"
printf '%s\n' "$selected_adjective" > "$dotfile"
fi
IFS=':' read -r adjective classification <<< "$selected_adjective"
day_of_week=$(date '+%A')
day_of_month=$(date '+%d')
month_name=$(date '+%B')
year=$(date '+%Y')
case "$day_of_month" in
1[0-9]) day_suffix="th" ;;
*1) day_suffix="st" ;;
*2) day_suffix="nd" ;;
*3) day_suffix="rd" ;;
*) day_suffix="th" ;;
esac
case "$classification" in
positive) text_color="$_BRIGHT_GREEN" ;;
negative) text_color="$_BRIGHT_RED" ;;
*) text_color="" ;;
esac
full_date="Pray, be informed, on this ${text_color}${adjective}${_NC} day,\n${_BLUE}${day_of_week}${_NC} the ${_BLUE}${day_of_month}${day_suffix}${_NC} day of ${_BLUE}${month_name}${_NC}, in the year of our Lord ${_BLUE}${year}${_NC}!"
printf '%b\n\n' "$full_date"
}
show_date