Created
May 9, 2023 12:50
-
-
Save ProxyAi/2ddc1761b41ffd6753ed2f5d953c20f1 to your computer and use it in GitHub Desktop.
Simple bash terminal calendar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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