summaryrefslogtreecommitdiff
path: root/ar/.local/bin
diff options
context:
space:
mode:
authorTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2026-03-26 13:51:38 +0900
committerTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2026-03-26 13:51:38 +0900
commitf60c21b17c0de2f0cf05f65dec23857d2947fb55 (patch)
treefb44faa2272dfd1552bc12d0b9d91fb795327c4e /ar/.local/bin
parent67a868697148fcbadadf45e638ab4b8a0b16a24e (diff)
modified statusbar/sb-clock, modified statusbar/sb-forecast
Diffstat (limited to 'ar/.local/bin')
-rwxr-xr-xar/.local/bin/statusbar/sb-clock11
-rwxr-xr-xar/.local/bin/statusbar/sb-forecast6
2 files changed, 11 insertions, 6 deletions
diff --git a/ar/.local/bin/statusbar/sb-clock b/ar/.local/bin/statusbar/sb-clock
index ddfa28b..d2d24e5 100755
--- a/ar/.local/bin/statusbar/sb-clock
+++ b/ar/.local/bin/statusbar/sb-clock
@@ -57,10 +57,12 @@ fi
locationfile="${XDG_CACHE_HOME:-${HOME}/.cache}/statusbar/location"
moonfile="${XDG_DATA_HOME:-${HOME}/.local/share}/wallpapers/moonphase"
-# Cache location for 24 hours
-if [ ! -s "$locationfile" ] || [ $(($(date +%s) - $(stat -c %Y "$locationfile" 2>/dev/null || echo 0))) -gt 86400 ]; then
+# Cache location for 24 hours - stores lat,lon
+valid_latlon() { echo "$1" | grep -qE '^-?[0-9]+\.?[0-9]*,-?[0-9]+\.?[0-9]*$'; }
+if ! ([ -s "$locationfile" ] && valid_latlon "$(cat "$locationfile")" && [ $(($(date +%s) - $(stat -c %Y "$locationfile" 2>/dev/null || echo 0))) -le 86400 ]); then
mkdir -p "${XDG_CACHE_HOME:-${HOME}/.cache}/statusbar"
- curl -s --max-time 2 http://ip-api.com/json | jq -r '[.regionName, .countryCode] | join(",")' >"$locationfile" 2>/dev/null &
+ loc=$(curl -s --max-time 2 http://ip-api.com/json 2>/dev/null | jq -r 'select(.status == "success") | [.lat, .lon] | join(",")' 2>/dev/null)
+ valid_latlon "$loc" && echo "$loc" >"$locationfile" &
fi
location=$(cat "$locationfile" 2>/dev/null || echo "")
@@ -68,7 +70,8 @@ location=$(cat "$locationfile" 2>/dev/null || echo "")
# Update moon phase only once per day
if [ ! -s "$moonfile" ] || [ "$(stat -c %y "$moonfile" 2>/dev/null | cut -d' ' -f1)" != "$(date '+%Y-%m-%d')" ]; then
if [ -n "$location" ]; then
- moon=$(curl -sf --max-time 2 "wttr.in/$location?format=%m" 2>/dev/null)
+ lat=${location%%,*} lon=${location##*,}
+ moon=$(curl -sf --max-time 2 "wttr.in/${lat},${lon}?format=%m" 2>/dev/null)
[ -n "$moon" ] && ! echo "$moon" | grep -q 'Unknown location' && echo "$moon" >"$moonfile" &
fi
fi
diff --git a/ar/.local/bin/statusbar/sb-forecast b/ar/.local/bin/statusbar/sb-forecast
index 061b095..6d9b086 100755
--- a/ar/.local/bin/statusbar/sb-forecast
+++ b/ar/.local/bin/statusbar/sb-forecast
@@ -6,9 +6,11 @@
# Cache location for 24 hours - stores lat,lon
locationfile="${XDG_CACHE_HOME:-${HOME}/.cache}/statusbar/location"
-if [ ! -s "$locationfile" ] || [ $(($(date +%s) - $(stat -c %Y "$locationfile" 2>/dev/null || echo 0))) -gt 86400 ]; then
+valid_latlon() { echo "$1" | grep -qE '^-?[0-9]+\.?[0-9]*,-?[0-9]+\.?[0-9]*$'; }
+if ! ([ -s "$locationfile" ] && valid_latlon "$(cat "$locationfile")" && [ $(($(date +%s) - $(stat -c %Y "$locationfile" 2>/dev/null || echo 0))) -le 86400 ]); then
mkdir -p "${XDG_CACHE_HOME:-${HOME}/.cache}/statusbar"
- curl -s http://ip-api.com/json 2>/dev/null | jq -r '[.lat, .lon] | join(",")' >"$locationfile" 2>/dev/null || true
+ loc=$(curl -s http://ip-api.com/json 2>/dev/null | jq -r 'select(.status == "success") | [.lat, .lon] | join(",")' 2>/dev/null)
+ valid_latlon "$loc" && echo "$loc" >"$locationfile"
fi
location=$(cat "$locationfile" 2>/dev/null || echo "")