diff options
| author | Maks Jopek <maks@jopek.eu> | 2026-07-12 15:30:03 +0200 |
|---|---|---|
| committer | Maks Jopek <maks@jopek.eu> | 2026-07-12 15:30:03 +0200 |
| commit | 497f40ed5a286e52383cc77e81aa1f49b74df925 (patch) | |
| tree | b22ecddb58d2bac5be1285f10f4e0e7e44db6690 /.local/bin/statusbar/sb-moonphase | |
| parent | cfe0107b0b47cff187ffef91d1ae6e4d5566b370 (diff) | |
| parent | 0e8bd85602cbe3f894d0cf5b0ce8af5cda40fd66 (diff) | |
| download | eibhear-master.tar.gz eibhear-master.tar.zst eibhear-master.zip | |
Diffstat (limited to '.local/bin/statusbar/sb-moonphase')
| -rwxr-xr-x | .local/bin/statusbar/sb-moonphase | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/.local/bin/statusbar/sb-moonphase b/.local/bin/statusbar/sb-moonphase index d496ae2..145c1b7 100755 --- a/.local/bin/statusbar/sb-moonphase +++ b/.local/bin/statusbar/sb-moonphase @@ -4,8 +4,27 @@ moonfile="${XDG_DATA_HOME:-$HOME/.local/share}/moonphase" -[ -s "$moonfile" ] && [ "$(stat -c %y "$moonfile" 2>/dev/null | cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] || - { curl -sf "wttr.in/?format=%m" > "$moonfile" || exit 1 ;} +checkmoon() { + [ "$(stat -c %y "$moonfile" 2>/dev/null | + cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] +} + +getmoon() { { grep -q -m1 '^up$' /sys/class/net/w*/operstate || grep -q -m1 '^up$' /sys/class/net/e*/operstate; } && + curl -sf "wttr.in/?format=%m" --output "$moonfile" && touch "$moonfile" +} + +checkmoon || + ( flock -n 9 && + ( tries=0; while [ $tries -ne 100 ]; do + # shellcheck disable=SC2015 + getmoon && break || + { tries=$((tries+1)); sleep .1; } + done + ! checkmoon && + until getmoon; do sleep 60; done + pkill -RTMIN+"${1:-17}" "${STATUSBAR:-dwmblocks}" + ) & + echo; exit ) 9>"${XDG_RUNTIME_DIR}/sb-moonphase.lock" icon="$(cat "$moonfile")" |
