Skip to content

Instantly share code, notes, and snippets.

@xorenio
Created May 9, 2023 12:50
Show Gist options
  • Save xorenio/2ddc1761b41ffd6753ed2f5d953c20f1 to your computer and use it in GitHub Desktop.
Save xorenio/2ddc1761b41ffd6753ed2f5d953c20f1 to your computer and use it in GitHub Desktop.
Simple bash terminal calendar
#!/bin/bash
# Get current year and month
year=$(date +%Y)
month=$(date +%m)
# Print month and year
echo "$(date +%B\ %Y)"
# Print the days of the week
echo "Su Mo Tu We Th Fr Sa"
# Get the first day of the month
first_day=$(date -d "$year-$month-01" +%w)
# Create the calendar
for ((i=0; i<$first_day; i++)); do
printf " "
done
for ((day=1; day<=31; day++)); do
if (( day < 10 )); then
printf " "
fi
if (( day == $(date +%e) && month == $(date +%m) )); then
printf "\e[7m%s\e[0m " $day
else
printf "%s " $day
fi
if (( $(($day+$first_day)) % 7 == 0 )); then
printf "\n"
fi
done
printf "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment