Twitter icon LinkedIn Icon Github Icon Stackoverflow Icon

Command Line Weather

By: Roger Creasy

If you live in the command line, like I do, anything that keeps you from having to leave it is a good thing. I am not a weather junkie. But, I often want to know if it is going to rain during my commute, or if I am going to be able to enjoy the outdoors when I get home.

I found the site which lets you git ascii weather info from the command line. You can specify any location by name, ZIP code, etc. Try running (from the command line) `curl`. Or,  `curl`.

I write a bash function to simplify the call for me. I wrote it so that it can either accept a location. If no location is given, it defaults to my home ZIP code. Here is my function:

weather() {                                                                                                                                                              
    if [ $# -eq 0 ]; then                                                                                                                                             

From the command line I can type `weather` and get the current weather and forecast  for my home ZIP. Or, I can type `weather north+pole` to get the weather at the North Pole.

To use this function, add the above to your shell startup script -- .bashrc, .zshrc, etc. Or, your functions script, if you have your startup script set up to source it. You'll also want to change the default ZIP code to the one you want to get by default... unless you want to know what weather I am experiencing.

I hope you find this useful. If you do, please share this post.

Publication Date: 2018-08-01 14:37:55