Heading image for post: Daily Update in the terminal

Daily Update in the terminal

Profile picture of Craig Hafer

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

image

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:

image

If you want to see a specific month, you can use cal mm yyyy, like so:

![image](https://i.imgur.com/FvAFSMf.png)

If you want to see a calendar view of the entire year, you can use cal yyyy, like so:

![image](https://i.imgur.com/vxZigea.png)

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.

image

If you want the calendar to show the previous, current, and next month, use this alias instead:

alias daily="weather && echo "" && cal -3" 

image

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:

![image](https://i.imgur.com/0BehcW1.png)

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

More posts about Command Line

  • Adobe logo
  • Barnes and noble logo
  • Aetna logo
  • Vanderbilt university logo
  • Ericsson logo

We're proud to have launched hundreds of products for clients such as LensRentals.com, Engine Yard, Verisign, ParkWhiz, and Regions Bank, to name a few.

Let's talk about your project