Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions bin/omarchy-menu-weather
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

# omarchy:summary=Pick a weather location via walker prompt and persist it
# omarchy:group=menu
# omarchy:examples=omarchy menu weather

set -eo pipefail

input=$(omarchy-menu-input "Weather location (city or zip)" || true)

[[ -z $input ]] && exit 0

omarchy weather set-location "$input"
17 changes: 17 additions & 0 deletions bin/omarchy-weather-clear-location
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

# omarchy:summary=Clear the configured weather location and return to auto-detect
# omarchy:examples=omarchy weather clear-location

set -eo pipefail

path="$HOME/.config/omarchy/current/weather.location"

if [[ -f $path ]]; then
rm -f "$path"
echo "Weather location cleared (using auto-detect)"
echo "Restarting Waybar..."
omarchy-restart-waybar
else
echo "No weather location was configured"
fi
5 changes: 4 additions & 1 deletion bin/omarchy-weather-icon
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

# omarchy:summary=Returns a weather condition icon, adjusted for live sunrise and sunset.

weather_data=$(curl -fsS --max-time 3 "https://wttr.in?format=j1" 2>/dev/null | jq -er '[.current_condition[0].weatherCode, .weather[0].astronomy[0].sunrise, .weather[0].astronomy[0].sunset] | select(all(. != null and . != "")) | @tsv' 2>/dev/null) || exit 1
loc=$(cat "$HOME/.config/omarchy/current/weather.location" 2>/dev/null || true)
loc_path="${loc:+/${loc// /+}}"

weather_data=$(curl -fsS --max-time 3 "https://wttr.in${loc_path}?format=j1" 2>/dev/null | jq -er '[.current_condition[0].weatherCode, .weather[0].astronomy[0].sunrise, .weather[0].astronomy[0].sunset] | select(all(. != null and . != "")) | @tsv' 2>/dev/null) || exit 1

IFS=$'\t' read -r weather_code sunrise sunset <<< "$weather_data"
if [[ ! $weather_code =~ ^[0-9]+$ || ! $sunrise =~ ^[0-9]{1,2}:[0-9]{2}\ [AP]M$ || ! $sunset =~ ^[0-9]{1,2}:[0-9]{2}\ [AP]M$ ]]; then
Expand Down
12 changes: 12 additions & 0 deletions bin/omarchy-weather-location
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

# omarchy:summary=Show currently configured weather location
# omarchy:examples=omarchy weather location

path="$HOME/.config/omarchy/current/weather.location"

if [[ -f $path ]]; then
cat "$path"
else
echo "Not configured"
fi
21 changes: 21 additions & 0 deletions bin/omarchy-weather-set-location
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

# omarchy:summary=Set the weather location used by waybar weather widgets
# omarchy:args=<location>
# omarchy:examples=omarchy weather set-location "New York, NY" | omarchy weather set-location London | omarchy weather set-location 10001

set -eo pipefail

location="$1"

if [[ -z $location ]]; then
echo "Usage: omarchy weather set-location <location>" >&2
exit 1
fi

mkdir -p "$HOME/.config/omarchy/current"
printf '%s\n' "$location" >"$HOME/.config/omarchy/current/weather.location"

echo "Weather location set to $location"
echo "Restarting Waybar..."
omarchy-restart-waybar
5 changes: 4 additions & 1 deletion bin/omarchy-weather-status
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

# omarchy:summary=Returns a formatted weather status string with temperature and wind speed.

weather=$(curl -fsS --max-time 4 "https://wttr.in?format=%l|%t|%w" 2>/dev/null | tr -d '\n')
loc=$(cat "$HOME/.config/omarchy/current/weather.location" 2>/dev/null || true)
loc_path="${loc:+/${loc// /+}}"

weather=$(curl -fsS --max-time 4 "https://wttr.in${loc_path}?format=%l|%t|%w" 2>/dev/null | tr -d '\n')

if [[ -z $weather ]]; then
echo "Weather unavailable"
Expand Down