Here’s a quick method to add your local weather report to your tmux status line. First, have a look at the lower right of this screenshot to see what we’re talking about:
Okay, here are the commands we’ll be using, all of which are either already installed or likely available in your favorite package manager:
Here are the steps, assuming everything’s installed:
- Create a small shell script called “gettemp.sh”.
- Add a line to your .tmux.conf file that calls and displays the results of the gettemp.sh script.
- There is no Step 3.
So, Step 1 — save this code in an executable file in your path:
weather -i KLAX | grep Temperature | sed 's/ Temperature: //g'
There are three parts to this. First, running the weather command, which grabs the online weather report for KLAX. The full report looks like this:
$ weather -i KLAX
Current conditions at Los Angeles Interntl Airport, CA (KLAX)
Last updated Jul 08, 2011 - 01:53 AM EDT / 2011.07.08 0553 UTC
Temperature: 68.0 F (20.0 C)
Relative Humidity: 78%
Wind: from the WSW (240 degrees) at 7 MPH (6 KT)
Sky conditions: clear
Second, the script uses grep to find the line in the report showing the Temperature.
Third, the script removes the “Temperature: ” label, leaving the numerical temperature that we want to display.
Step 2, edit your .tmux.conf file. Now, if you already have a .tmux.conf file in your home directory, you might also have a line that starts
set -g status-right — that’s the line we’re going to edit.
Here’s an example .tmux.conf file with a good mix of commands and options set. Find the
set -g status-right line, which we’ll use as a starting point.
set -g status-right '#[fg=green]][ #[fg=blue]%Y-%m-%d #[fg=white]%H:%M#[default]'
As you can probably guess, this is showing the Year-month-day in green, then hours:minutes in white. We’ll leave the color alone and put the weather directly after the time thusly:
set -g status-right '#[fg=green]][ #[fg=blue]%Y-%m-%d #[fg=white]%H:%M # // #(gettemp.sh)#[default]'
(Note: this will only work if your gettemp.sh script is in your path; otherwise, you’ll have to specify a full path there.)
And that’s it!