aboutsummaryrefslogtreecommitdiffstats
path: root/config/hypr/scripts/Toggle-weather-waybar-units.sh
blob: 4007536c424dcb168f13cdd06e91e1730678327e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env bash
# Toggle waybar-weather units between metric and imperial

CONFIG_FILE="$HOME/.config/waybar-weather/config.toml"

if [ ! -f "$CONFIG_FILE" ]; then
  notify-send "Weather units" "Config not found: $CONFIG_FILE"
  exit 1
fi

# Determine current units (default to metric when unset/commented)
current_units="metric"
if grep -qE '^[[:space:]]*units[[:space:]]*=' "$CONFIG_FILE"; then
  current_units=$(sed -nE 's/^[[:space:]]*units[[:space:]]*=[[:space:]]*"([^"]+)".*/\1/p' "$CONFIG_FILE" | head -n1)
fi

if [ "$current_units" = "imperial" ]; then
  new_units="metric"
else
  new_units="imperial"
fi

# Update config: prefer replacing existing units line, otherwise uncomment default, else append
if grep -qE '^[[:space:]]*units[[:space:]]*=' "$CONFIG_FILE"; then
  sed -i 's/^[[:space:]]*units[[:space:]]*=.*/units = "'"$new_units"'"/' "$CONFIG_FILE"
elif grep -qE '^[[:space:]]*#\s*units[[:space:]]*=' "$CONFIG_FILE"; then
  sed -i 's/^[[:space:]]*#\s*units[[:space:]]*=.*/units = "'"$new_units"'"/' "$CONFIG_FILE"
else
  printf '\nunits = "%s"\n' "$new_units" >> "$CONFIG_FILE"
fi

pkill waybar-weather 2>/dev/null || true
notify-send "Weather units now ${new_units}" "Click on waybar-weather to update units"
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage