Daily Update in the terminal
I would like to share a few commands and aliases that have given me a convenient way to receive useful information, such as the weather and a calendar view.
Weather
Let’s start with viewing the local weather. A weather service I like to use is wttr.in. We can reach out to this service like so:
curl http://wttr.in/
This will nicely display the current weather, and a 3-day forecast. This service is provided by @igor_chubin
So, let’s go ahead and make this into a convenient alias.
alias weather="curl http://wttr.in/"
Calendar
If you are using Linux or Unix you already have access to the cal command. If you just enter cal
it will display a little calendar of the current month, with the current day being highlighted, like so:
If you want to see a specific month, you can use cal mm yyyy
, like so:
If you want to see a calendar view of the entire year, you can use cal yyyy
, like so:
Now that we see how the cal
command works, let’s implement it into a daily
alias that we can use to display the date and the weather.
alias daily="weather && echo "" && cal"
I add in the
echo ""
just to add a blank line between the the calendar and the weather update. To me this makes it appear a little bit cleaner, but it is ultimately up to your preference if you want to have that in there.
If you want the calendar to show the previous, current, and next month, use this alias instead:
alias daily="weather && echo "" && cal -3"
That’s it!
To me, it’s nice to have this little command available in the terminal, as that is where I do the majority of my work.
If you’re interested, here are a couple ways to make using cal
a bit nicer.
Calendar Year
Instead of typing out cal 2022
to see the current year (Assuming you are seeing this in 2022 😉) you can just pass -y
to grab the current year.
cal -y
Calendar Month
To get a calendar of a specific month, you have to use cal mm yyyy
.
I found I was getting annoyed because in my mind typing cal 12
should show me a calendar of December. However, you’ll find that it just gives you a full calendar of the year 12, which helps nobody.
function calm() {
month="$@"
current_year=$(date +'%Y')
cal "$month" $current_year
}
This function takes the input and stores it in the month variable, grabs the year from the system and stores it in the current_year variable, and then calls cal
with the month and the current year.
So you should now be able to use the calm mm
command to display whichever month you’d like, of the current year, like so:
Because it’s not necessary to store these values in variables, here is a refactored version of calm()
that would work exactly the same:
function calm() {
cal "$@" $(date +'%Y')
}
Conclusion
If you made it this far, you should now have aliases/functions for weather
, daily
, and calm
, and you should have an understanding of how the cal
command works. It’s not a game changer, but I hope you find this be a nice little tool that you can use.
Photo by: Renato Andrade Fernandes