Tmux Weather

I just added current weather to my tmux status line, and I am excite. Here’s how I did it.

The Code

There is some code. I started with a post that I found. Jezen’s code is pretty slick. It figures out your general location from your internet connection, and then pumps your coordinates into a weather API.

I changed the weather API to I also added some rate limiting because tmux updates the status bar frequently and I blew through my 1000 daily free API hits pretty fast. Now I hit the API about every 2 minutes and stash the info in a text file that I can read in one of the off cycle status refreshes.

# Weather
# =======
# Based on the work of...
# By Jezen Thomas

# This script sends a couple of requests over the network to retrieve
# approximate location data, and the current weather for that location. This is
# useful if for example you want to display the current weather in your tmux
# status bar.

# There are three things you will need to do before using this script.
# 1. Install jq with your package manager of choice (homebrew, apt-get, etc.)
# 2. Sign up for a free account with to grab your API key
# 3. Add your API key where it says API_KEY

# Limit the rate of calls to every 2 minutes
MINUTE=$(date +"%M")
if [ $((MINUTE%5)) -ne 2 ]; then
WEATHER_STATUS="cat ~/Dropbox/code/weather.txt"


set -e

weather_icon() {
case $1 in
clear-day) echo 😎
clear-night) echo 🌃
rain) echo ☔️
snow) echo ❄️
sleet|hail) echo 🌨
wind) echo 🌬
fog) echo 🌫
cloudy) echo ☁️
partly-cloudy-day) echo 🌥
partly-cloudy-night) echo ☁︎
thunderstorm) echo ⛈
tornado) echo 🌪
*) echo 🌎 $1

LOCATION=$(curl --silent
CITY=$(echo "$LOCATION" | cut -d , -f 6)
LAT=$(echo "$LOCATION" | cut -d , -f 8)
LON=$(echo "$LOCATION" | cut -d , -f 9)

WEATHER=$(curl --silent $URL)

SUMMARY=$(echo "$WEATHER" | jq .currently.summary | sed s/\"//g)
ICON=$(echo "$WEATHER" | jq .currently.icon | sed s/\"//g)
TEMP="$(echo "$WEATHER" | jq .currently.temperature | xargs printf "%.f\n" 0)°F"
WIND_SPEED="$(echo "$WEATHER" | jq .currently.windSpeed | xargs printf "%.
f" 0) MPH"
EMOJI=$(weather_icon $ICON)

echo $WEATHER_STATUS > ~/Dropbox/code/weather.txt

The emoji get messed up with the markdown interpretation, so here are all of them in one glorious weather string:


For my tmux configuration file I just added the call to the shell script in the right status:

set -g status-right '#($HOME/Dropbox/code/ | Batt: #{battery_icon} #{battery_percentage} #{battery_remain} | %a %h-%d %H:%M '

As you can see, I have some other stuff in there as well. You can see the full configuration file in my dotfiles repo. I put the weather script in my Dropbox folder and not in my dotfiles repo because it has the API key in there and security and I didn’t want to deal with environment variables across shells and tmux.


Behold it’s glory

Tmux Config

Leave a Comment

Filed under programming, Uncategorized