Unix3r

Build. Break. Learn. Repeat.

Starting0%
Skip to content

unix3r/dotfiles

Public
main
U Unix3r Initial commit: sway + waybar dotfiles (Catppuccin Mocha) eb290df
38 lines Β· 1.8 KB Raw History
1#!/usr/bin/env bash
2# weather.sh β€” waybar weather from wttr.in (no API key).
3# Set your city with WEATHER_LOCATION in ~/.config/environment.d or leave
4# empty for IP-based location. Units: m = metric, u = US.
5LOCATION=${WEATHER_LOCATION:-}
6UNITS=${WEATHER_UNITS:-m}
7cache="${XDG_CACHE_HOME:-$HOME/.cache}/waybar-weather.json"
8
9loc=${LOCATION// /+}
10if data=$(curl -sf --max-time 8 "https://wttr.in/${loc}?format=j1&${UNITS}"); then
11 echo "$data" > "$cache"
12elif [[ -f $cache ]]; then
13 data=$(cat "$cache")
14else
15 echo '{"text":"","tooltip":"weather unavailable"}'; exit 0
16fi
17
18jq -c --arg u "$UNITS" '
19 def icon(c):
20 {"113":"β˜€οΈ","116":"β›…","119":"☁️","122":"☁️","143":"🌫","248":"🌫","260":"🌫",
21 "176":"🌦","263":"🌦","266":"🌦","293":"🌦","296":"🌦","353":"🌦",
22 "299":"🌧","302":"🌧","305":"🌧","308":"🌧","356":"🌧","359":"🌧",
23 "179":"🌨","227":"🌨","230":"❄️","323":"🌨","326":"🌨","329":"❄️","332":"❄️",
24 "335":"❄️","338":"❄️","368":"🌨","371":"❄️",
25 "200":"β›ˆ","386":"β›ˆ","389":"β›ˆ","392":"β›ˆ","395":"❄️"}[c] // "🌑";
26 .current_condition[0] as $c
27 | .nearest_area[0] as $a
28 | (if $u == "u" then "Β°F" else "Β°C" end) as $deg
29 | (if $u == "u" then $c.temp_F else $c.temp_C end) as $t
30 | (if $u == "u" then $c.FeelsLikeF else $c.FeelsLikeC end) as $f
31 | {
32 text: "\(icon($c.weatherCode)) \($t)\($deg)",
33 tooltip: ("<b>\($a.areaName[0].value), \($a.country[0].value)</b>\n"
34 + "\($c.weatherDesc[0].value)\n"
35 + "Feels like \($f)\($deg) Β· Humidity \($c.humidity)%\n"
36 + "Wind \($c.windspeedKmph) km/h \($c.winddir16Point)\n\n"
37 + ([.weather[] | "\(.date): \(.mintempC)–\(.maxtempC)Β°C"] | join("\n")))
38 }' <<<"$data"