Skip to content
A Bash script to add regularly updated localized weather icons to your bash prompt
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
LocateMe
.gitignore
BashWeather.sh
LICENSE
README.md
RunLocateMe

README.md

BashWeather

A Bash script to add regularly updated localized weather icons to your bash prompt.

Pull requests welcome!

Program: BashWeather
Author: J.J.
Email: JJ@jdotjdot.com
Version 1.2

This script makes use of the following tools:

  • LocateMe for Mac OS X by Robert Harder
    • Includes both the source code as well as the pre-compiled XCode project
  • OpenWeatherMap's excellent weather API
  • Shellcheck.net -- excellent Bash debugging tool!
  • ip-api.com for IP geolocation The accuracy of BashWeather relies on OpenWeatherMap and, if using it, ip-api.com.

BashWeather screenshot

Screenshots of sample terminal sessions with BashWeather, note the moon

Known Issues:

  • Believed resolved Per this StackOverflow question, you may encounter bugs in certain terminal programs or versions of bash when writing past the end of a line, due to issues with unicode display. This is believed to be resolved by having removed the "umbrella with rain" character and replaced it with the regular umbrella.

##USAGE BashWeather.sh -h gives the following:

USAGE: Add . [/path/to/]BashWeather.sh [options] to your .bashrc, then include $WEATHERCHAR in your bash $PS1 variable somewhere below that. If you plan to use the provided RunLocateMe binary that makes use of Mac OS X's geolocation feature, make sure that it is located in the same directory as BashWeather.sh. Alternatively, if you simply wish to return the character, you can use the -e flag like printf "$(. [/path/to/]BashWeather.sh [options] -e )" to print the weather character.

OPTIONS:

  • -c <character> - default character to be displayed in your prompt should the weather not be available for any reason. Default character is the dollar sign ($). Please note that this will NOT become a hash (#) when root.
  • -l [<city, country> | LocateMe] - switch to instead supply your city and country in a string for location checking (e.g., "London, UK").
    • To have BashWeather check your location via the Mac built-in utility, use -l LocateMe.
    • Default is to use your IP address. Note that this will be inaccurate if using a proxy.
  • -u <integer> - how often, in seconds, to wait between weather updates. Default is 10800 (3 hours).
  • -s <string> - a string, like "(weather updated)", to display only when the weather has just been updated. No default.
  • -t <integer> - timeout, in seconds, for any HTTP requests made by BashWeather. Make this value smaller if you want a shorter delay when no internet is available or is too slow. Default is 1.
  • -e - echo the resulting character instead. This does not save to WEATHERCHAR.
  • -h - display the help.

BashWeather will create the following global variables in Bash:

  • LAST_TIME_CHECKED_WEATHER - to store the last time the weather was updated
  • LAT - latitude
  • LON - longitude
  • WEATHERCHAR - a variable containing the appropriate weather character for you to include in your bash prompt as you see fit.
You can’t perform that action at this time.