Linux

Weather info in i3status

I recently started using i3wm because it is light-weight, keyboard-friendly and uses the screen real-estate efficiently.  I customized i3bar and i3status (which came installed with i3) to show system information and date/time. But there was no out-of-the-box feature to get weather information from i3 status.

I wanted a simple solution that does not require installing an external program like i3blocksconky, dzen2, xmobar or lemonbar. It had to also preserve colors I had configured for the i3bar output. So I came up with this simple solution.

Step 1: Setup a cron job to retrieve weather information every half hour and store it in a temporary file.

*/5 * * * * curl -s wttr.in/montreal?T | head -n 7 > ~/.weather.cache

Step 2: Write a shell script to add this information to i3status data.

  
 #!/bin/sh
# shell script to prepend i3status with weather

i3status | (read line && echo "$line" && read line && echo "$line" && read line && echo "$line" && while :
do
  read line
  temp=$(cat ~/.weather.cache | grep -m 1 -Eo -e '-?[[:digit:]].*°C')
  status=$(cat ~/.weather.cache | head -n 3 | tail -n 1 | cut -c 16-)
  echo ",[{\"full_text\":\"${temp} ? ${status}\",\"color\":\"#00FF00\" },${line#,\[}" || exit 1
done)

Step 3: The~/.config/i3/config file needs to be updated for thestatus_command to pipe through this script, as follows.

 
bar {
status_command .config/i3/weather.sh
tray_output primary
}

Step 4: The~/.i3status.conf file should also be updated to change the output to the JSON format.

 
general {
output_format = "i3bar"
colors = true
interval = 5
}

You can find more information from the following links.

Published on System Code Geeks with permission by Keheliya Gallaba, partner at our SCG program. See the original article here: Weather info in i3status

Opinions expressed by System Code Geeks contributors are their own.

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
bilibraker
bilibraker
2 years ago

Thank you for this, works smoothly!
However, there is an unnecessary “?” at the 9th line of weather.sh before “${status}”

Last edited 2 years ago by bilibraker
Back to top button