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

16
bashrc
View File

@ -7,6 +7,15 @@ export SHELL_CONFIG="$SHELL_CONFIG:.bashrc"
# #
function show_date() { function show_date() {
# Define the dot file to store the selected adjective
dotfile="$HOME/.adjective_of_the_day"
# Check if the dot file exists and was modified less than 1 day ago
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 # Define an array of adjectives with classifications
adjectives=( adjectives=(
"beautiful:positive" "beautiful:positive"
@ -46,6 +55,10 @@ function show_date() {
# Select a random adjective from the array # Select a random adjective from the array
selected_adjective="${adjectives[$RANDOM % ${#adjectives[@]}]}" selected_adjective="${adjectives[$RANDOM % ${#adjectives[@]}]}"
# Store the selected adjective in the dot file
echo "$selected_adjective" > "$dotfile"
fi
# Split the selected adjective into the adjective and classification parts # Split the selected adjective into the adjective and classification parts
IFS=':' read -r adjective classification <<< "$selected_adjective" IFS=':' read -r adjective classification <<< "$selected_adjective"
@ -76,13 +89,14 @@ function show_date() {
esac esac
# Create the full date format with colored parts and the selected adjective # 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, ${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}!" 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 # Print the full date
echo -e "$full_date" echo -e "$full_date"
echo "" echo ""
} }
# If not running interactively, don't do anything # If not running interactively, don't do anything
[[ $- != *i* ]] && return [[ $- != *i* ]] && return