This commit is contained in:
Ray Elliott 2023-09-17 19:01:58 +01:00
parent 5d4f6daef9
commit 98e1ee645a
1 changed files with 80 additions and 66 deletions

146
bashrc
View File

@ -7,82 +7,96 @@ export SHELL_CONFIG="$SHELL_CONFIG:.bashrc"
# #
function show_date() { function show_date() {
# Define an array of adjectives with classifications # Define the dot file to store the selected adjective
adjectives=( dotfile="$HOME/.adjective_of_the_day"
"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"
)
# Select a random adjective from the array # Check if the dot file exists and was modified less than 1 day ago
selected_adjective="${adjectives[$RANDOM % ${#adjectives[@]}]}" if [[ -f "$dotfile" && $(date -d "$(stat -c %y "$dotfile")" +%s) -ge $(date -d 'yesterday' +%s) ]]; then
# If the dot file exists and was modified less than 1 day ago,
# read the stored adjective from the file
selected_adjective=$(cat "$dotfile")
else
# Define an array of adjectives with classifications
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"
)
# Split the selected adjective into the adjective and classification parts # Select a random adjective from the array
IFS=':' read -r adjective classification <<< "$selected_adjective" selected_adjective="${adjectives[$RANDOM % ${#adjectives[@]}]}"
# Determine the color code based on the classification # Store the selected adjective in the dot file
case "$classification" in echo "$selected_adjective" > "$dotfile"
"positive") text_color="\033[1;32m";; fi
"negative") text_color="\033[1;31m";;
*) text_color="";; # Default to no colour
esac
# ANSI escape codes for reset # Split the selected adjective into the adjective and classification parts
reset_color='\033[0m' IFS=':' read -r adjective classification <<< "$selected_adjective"
hl_color='\033[1;34m'
# Get the current day of the week, day of the month, and year # Determine the color code based on the classification
day_of_week=$(date "+%A") case "$classification" in
day_of_month=$(date "+%d") "positive") text_color="\033[1;32m";;
month_name=$(date "+%B") "negative") text_color="\033[1;31m";;
year=$(date "+%Y") *) text_color="";; # Default to no colour
esac
# Determine the day suffix (th, nd, rd) # ANSI escape codes for reset
case "$day_of_month" in reset_color='\033[0m'
1[0-9]) day_suffix="th";; hl_color='\033[1;34m'
*1) day_suffix="st";;
*2) day_suffix="nd";;
*3) day_suffix="rd";;
*) day_suffix="th";;
esac
# Create the full date format with colored parts and the selected adjective # Get the current day of the week, day of the month, and year
full_date="Pray, be informed, on this ${text_color}${adjective}${reset_color} day, ${hl_color}${day_of_week}${reset_color} the ${hl_color}${day_of_month}${day_suffix}${reset_color} day of ${hl_color}${month_name}${reset_color}, in the year of our Lord ${hl_color}${year}${reset_color}!" day_of_week=$(date "+%A")
day_of_month=$(date "+%d")
month_name=$(date "+%B")
year=$(date "+%Y")
# Print the full date # Determine the day suffix (th, nd, rd)
echo -e "$full_date" case "$day_of_month" in
echo "" 1[0-9]) day_suffix="th";;
*1) day_suffix="st";;
*2) day_suffix="nd";;
*3) day_suffix="rd";;
*) day_suffix="th";;
esac
# Create the full date format with colored parts and the selected adjective
full_date="Pray, be informed, on this ${text_color}${adjective}${reset_color} day,\n${hl_color}${day_of_week}${reset_color} the ${hl_color}${day_of_month}${day_suffix}${reset_color} day of ${hl_color}${month_name}${reset_color}, in the year of our Lord ${hl_color}${year}${reset_color}!"
# Print the full date
echo -e "$full_date"
echo ""
} }
# If not running interactively, don't do anything # If not running interactively, don't do anything
[[ $- != *i* ]] && return [[ $- != *i* ]] && return