From d1054d839ec3c067f6f79c2f40c62aa99cbe7ba2 Mon Sep 17 00:00:00 2001 From: appeasementPolitik <108810900+appeasementPolitik@users.noreply.github.com> Date: Sun, 2 Apr 2023 11:53:46 +0000 Subject: [PATCH 01/11] Make dwmblocks modules async --- .local/bin/statusbar/sb-forecast | 4 +--- .local/bin/statusbar/sb-iplocate | 3 ++- .local/bin/statusbar/sb-moonphase | 2 +- .local/bin/statusbar/sb-price | 21 ++++++++++++++++----- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/.local/bin/statusbar/sb-forecast b/.local/bin/statusbar/sb-forecast index 2b41b3d7..582af2b5 100755 --- a/.local/bin/statusbar/sb-forecast +++ b/.local/bin/statusbar/sb-forecast @@ -48,6 +48,4 @@ case $BLOCK_BUTTON in 6) "$TERMINAL" -e "$EDITOR" "$0" ;; esac -checkforecast || getforecast - -showweather +checkforecast && showweather || { ( getforecast && pkill -RTMIN+5 "${STATUSBAR:-dwmblocks}") & echo; } diff --git a/.local/bin/statusbar/sb-iplocate b/.local/bin/statusbar/sb-iplocate index 02adab8d..a6eb76fc 100755 --- a/.local/bin/statusbar/sb-iplocate +++ b/.local/bin/statusbar/sb-iplocate @@ -6,5 +6,6 @@ # https://www.maketecheasier.com/ip-address-geolocation-lookups-linux/ ifinstalled "geoip" || exit -addr="$(curl ifconfig.me 2>/dev/null)" || exit +ipfile="$XDG_RUNTIME_DIR/iplocate" +addr=$(cat "$ipfile") && rm "$ipfile" || { ( curl -s ifconfig.me > "$ipfile" && pkill -RTMIN+27 "${STATUSBAR:-dwmblocks}") & echo; exit; } grep "flag: " "${XDG_DATA_HOME:-$HOME/.local/share}/larbs/emoji" | grep "$(geoiplookup "$addr" | sed 's/.*, //')" | sed "s/flag: //;s/;.*//" diff --git a/.local/bin/statusbar/sb-moonphase b/.local/bin/statusbar/sb-moonphase index 99adaee8..7b939feb 100755 --- a/.local/bin/statusbar/sb-moonphase +++ b/.local/bin/statusbar/sb-moonphase @@ -5,7 +5,7 @@ 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 ;} + { ( curl -sf "wttr.in/?format=%m" > "$moonfile" && pkill -RTMIN+17 "${STATUSBAR:-dwmblocks}" ) & echo; exit; } icon="$(cat "$moonfile")" diff --git a/.local/bin/statusbar/sb-price b/.local/bin/statusbar/sb-price index 9dc2d527..7304de8f 100755 --- a/.local/bin/statusbar/sb-price +++ b/.local/bin/statusbar/sb-price @@ -18,7 +18,7 @@ filestat="$(stat -c %x "$pricefile" 2>/dev/null)" [ -d "$dir" ] || mkdir -p "$dir" -updateprice() { curl -sf -m 1 --fail-early $currency.$url/{1$1,$1$interval} --output "$pricefile" --output "$chartfile" || +updateprice() { curl -sf $currency.$url/{1$1,$1$interval} --output "$pricefile" --output "$chartfile" || rm -f "$pricefile" "$chartfile" ;} [ "${filestat%% *}" != "$(date '+%Y-%m-%d')" ] && @@ -38,10 +38,21 @@ case $BLOCK_BUTTON in esac [ -n "$updateme" ] && - updateprice "$1" && - [ -n "$showupdate" ] && - notify-send "$3 Update complete." "$2 price is now -\$$(cat "$pricefile")" + if [ -n "$showupdate" ]; then + updateprice "$1" && notify-send "$3 Update complete." "$2 price is now \$$(cat "$pricefile")" + else + # get dwmblocks signal numbers corresponding to currency + case "$1" in + lbc) sig="22" ;; + bat) sig="20" ;; + link) sig="25" ;; + xmr) sig="24" ;; + eth) sig="23" ;; + btc) sig="21" ;; + esac + + ( updateprice "$1" && pkill -RTMIN+"$sig" "${STATUSBAR:-dwmblocks}") & echo; exit + fi case "$currency" in usd) symb="$" ;; From 0e237592d74fb9b505231bbb4bd2649da0aab8ea Mon Sep 17 00:00:00 2001 From: appeasementPolitik <108810900+appeasementPolitik@users.noreply.github.com> Date: Tue, 4 Apr 2023 07:25:19 +0000 Subject: [PATCH 02/11] Allow dwmblocks signal numbers to be changed --- .local/bin/statusbar/sb-forecast | 2 +- .local/bin/statusbar/sb-iplocate | 2 +- .local/bin/statusbar/sb-moonphase | 2 +- .local/bin/statusbar/sb-price | 34 +++++++++++-------------------- 4 files changed, 15 insertions(+), 25 deletions(-) diff --git a/.local/bin/statusbar/sb-forecast b/.local/bin/statusbar/sb-forecast index 582af2b5..5426e60d 100755 --- a/.local/bin/statusbar/sb-forecast +++ b/.local/bin/statusbar/sb-forecast @@ -48,4 +48,4 @@ case $BLOCK_BUTTON in 6) "$TERMINAL" -e "$EDITOR" "$0" ;; esac -checkforecast && showweather || { ( getforecast && pkill -RTMIN+5 "${STATUSBAR:-dwmblocks}") & echo; } +checkforecast && showweather || { ( getforecast && pkill -RTMIN+"${1:-5}" "${STATUSBAR:-dwmblocks}") & echo; } diff --git a/.local/bin/statusbar/sb-iplocate b/.local/bin/statusbar/sb-iplocate index a6eb76fc..46e69507 100755 --- a/.local/bin/statusbar/sb-iplocate +++ b/.local/bin/statusbar/sb-iplocate @@ -7,5 +7,5 @@ ifinstalled "geoip" || exit ipfile="$XDG_RUNTIME_DIR/iplocate" -addr=$(cat "$ipfile") && rm "$ipfile" || { ( curl -s ifconfig.me > "$ipfile" && pkill -RTMIN+27 "${STATUSBAR:-dwmblocks}") & echo; exit; } +addr=$(cat "$ipfile") && rm "$ipfile" || { ( curl -s ifconfig.me > "$ipfile" && pkill -RTMIN+"${1:-27}" "${STATUSBAR:-dwmblocks}") & echo; exit; } grep "flag: " "${XDG_DATA_HOME:-$HOME/.local/share}/larbs/emoji" | grep "$(geoiplookup "$addr" | sed 's/.*, //')" | sed "s/flag: //;s/;.*//" diff --git a/.local/bin/statusbar/sb-moonphase b/.local/bin/statusbar/sb-moonphase index 7b939feb..635b8608 100755 --- a/.local/bin/statusbar/sb-moonphase +++ b/.local/bin/statusbar/sb-moonphase @@ -5,7 +5,7 @@ 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" && pkill -RTMIN+17 "${STATUSBAR:-dwmblocks}" ) & echo; exit; } + { ( curl -sf "wttr.in/?format=%m" > "$moonfile" && pkill -RTMIN+"${1:-17}" "${STATUSBAR:-dwmblocks}" ) & echo; exit; } icon="$(cat "$moonfile")" diff --git a/.local/bin/statusbar/sb-price b/.local/bin/statusbar/sb-price index 7304de8f..d5aa0e52 100755 --- a/.local/bin/statusbar/sb-price +++ b/.local/bin/statusbar/sb-price @@ -1,19 +1,19 @@ #!/bin/sh # Usage: -# price -# price bat "Basic Attention Token" 🦁 +# price +# price 20 bat "Basic Attention Token" 🦁 # When the name of the currency is multi-word, put it in quotes. -[ -z "$3" ] && exit 1 +[ -z "$4" ] && exit 1 -# use $4 as currency, if not passed in use "usd" as default +# use $5 as currency, if not passed in use "usd" as default url="${CRYPTOURL:-rate.sx}" -currency="${4:-usd}" +currency="${5:-usd}" interval="@14d" # History contained in chart preceded by '@' (7d = 7 days) dir="${XDG_CACHE_HOME:-$HOME/.cache}/crypto-prices" -pricefile="$dir/$1-$currency" -chartfile="$dir/$1-$currency-chart" +pricefile="$dir/$2-$currency" +chartfile="$dir/$2-$currency-chart" filestat="$(stat -c %x "$pricefile" 2>/dev/null)" [ -d "$dir" ] || mkdir -p "$dir" @@ -26,9 +26,9 @@ updateprice() { curl -sf $currency.$url/{1$1,$1$interval} --output "$pricefile" case $BLOCK_BUTTON in 1) setsid "$TERMINAL" -e less -Srf "$chartfile" ;; - 2) notify-send -u low "$3 Updating..." "Updating $2 price..." ; updateme="1" ; showupdate="1" ;; + 2) notify-send -u low "$4 Updating..." "Updating $3 price..." ; updateme="1" ; showupdate="1" ;; 3) uptime="$(date -d "$filestat" '+%D at %T' | sed "s|$(date '+%D')|Today|")" - notify-send "$3 $2 module" "\- Exact price: \$$(cat "$pricefile") + notify-send "$4 $3 module" "\- Exact price: \$$(cat "$pricefile") - Left click for chart of changes. - Middle click to update. - Shows 🔃 if updating prices. @@ -39,19 +39,9 @@ esac [ -n "$updateme" ] && if [ -n "$showupdate" ]; then - updateprice "$1" && notify-send "$3 Update complete." "$2 price is now \$$(cat "$pricefile")" + updateprice "$2" && notify-send "$4 Update complete." "$3 price is now \$$(cat "$pricefile")" else - # get dwmblocks signal numbers corresponding to currency - case "$1" in - lbc) sig="22" ;; - bat) sig="20" ;; - link) sig="25" ;; - xmr) sig="24" ;; - eth) sig="23" ;; - btc) sig="21" ;; - esac - - ( updateprice "$1" && pkill -RTMIN+"$sig" "${STATUSBAR:-dwmblocks}") & echo; exit + ( updateprice "$2" && pkill -RTMIN+"$1" "${STATUSBAR:-dwmblocks}") & echo; exit fi case "$currency" in @@ -61,4 +51,4 @@ case "$currency" in btc) symb="" ;; esac -[ -f "$pricefile" ] && printf "$3$symb%0.2f" "$(cat "$pricefile")" +[ -f "$pricefile" ] && printf "$4$symb%0.2f" "$(cat "$pricefile")" From e3a5d38200cb4590d21d0760297a89237b4cd350 Mon Sep 17 00:00:00 2001 From: appeasementPolitik <108810900+appeasementPolitik@users.noreply.github.com> Date: Wed, 5 Apr 2023 08:09:57 +0000 Subject: [PATCH 03/11] Become synchronous on manual run and make dwmblocks signal code optional --- .local/bin/statusbar/sb-price | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/.local/bin/statusbar/sb-price b/.local/bin/statusbar/sb-price index d5aa0e52..e52dc56b 100755 --- a/.local/bin/statusbar/sb-price +++ b/.local/bin/statusbar/sb-price @@ -1,19 +1,22 @@ #!/bin/sh # Usage: -# price -# price 20 bat "Basic Attention Token" 🦁 +# price +# price bat "Basic Attention Token" 🦁 # When the name of the currency is multi-word, put it in quotes. -[ -z "$4" ] && exit 1 +[ -z "$3" ] && exit 1 + +# handle optional parameters in $4 and/or $5 +echo "$4" | grep -q '^[0-9]' && + currency='usd' && sig=$4 || + { currency="${4:-usd}"; sig=$5; } -# use $5 as currency, if not passed in use "usd" as default url="${CRYPTOURL:-rate.sx}" -currency="${5:-usd}" interval="@14d" # History contained in chart preceded by '@' (7d = 7 days) dir="${XDG_CACHE_HOME:-$HOME/.cache}/crypto-prices" -pricefile="$dir/$2-$currency" -chartfile="$dir/$2-$currency-chart" +pricefile="$dir/$1-$currency" +chartfile="$dir/$1-$currency-chart" filestat="$(stat -c %x "$pricefile" 2>/dev/null)" [ -d "$dir" ] || mkdir -p "$dir" @@ -26,9 +29,9 @@ updateprice() { curl -sf $currency.$url/{1$1,$1$interval} --output "$pricefile" case $BLOCK_BUTTON in 1) setsid "$TERMINAL" -e less -Srf "$chartfile" ;; - 2) notify-send -u low "$4 Updating..." "Updating $3 price..." ; updateme="1" ; showupdate="1" ;; + 2) notify-send -u low "$3 Updating..." "Updating $2 price..." ; updateme="1" ; showupdate="1" ;; 3) uptime="$(date -d "$filestat" '+%D at %T' | sed "s|$(date '+%D')|Today|")" - notify-send "$4 $3 module" "\- Exact price: \$$(cat "$pricefile") + notify-send "$3 $2 module" "\- Exact price: \$$(cat "$pricefile") - Left click for chart of changes. - Middle click to update. - Shows 🔃 if updating prices. @@ -39,9 +42,11 @@ esac [ -n "$updateme" ] && if [ -n "$showupdate" ]; then - updateprice "$2" && notify-send "$4 Update complete." "$3 price is now \$$(cat "$pricefile")" + updateprice "$1" && notify-send "$3 Update complete." "$2 price is now \$$(cat "$pricefile")" else - ( updateprice "$2" && pkill -RTMIN+"$1" "${STATUSBAR:-dwmblocks}") & echo; exit + [ -n "$sig" ] && + { ( updateprice "$1" && pkill -RTMIN+"$sig" "${STATUSBAR:-dwmblocks}" ) & echo; exit; } || + updateprice "$1" fi case "$currency" in @@ -51,4 +56,4 @@ case "$currency" in btc) symb="" ;; esac -[ -f "$pricefile" ] && printf "$4$symb%0.2f" "$(cat "$pricefile")" +[ -f "$pricefile" ] && printf "$3$symb%0.2f" "$(cat "$pricefile")" From b1ddd9548e4b33966336f41a16c54ad75dbf53e4 Mon Sep 17 00:00:00 2001 From: appeasementPolitik <108810900+appeasementPolitik@users.noreply.github.com> Date: Thu, 20 Apr 2023 17:11:58 +0000 Subject: [PATCH 04/11] Merge latest commits and add retries --- .local/bin/statusbar/sb-forecast | 2 +- .local/bin/statusbar/sb-iplocate | 10 +++++-- .local/bin/statusbar/sb-moonphase | 2 +- .local/bin/statusbar/sb-price | 50 +++++++++++++++---------------- 4 files changed, 34 insertions(+), 30 deletions(-) diff --git a/.local/bin/statusbar/sb-forecast b/.local/bin/statusbar/sb-forecast index 5426e60d..ba249a66 100755 --- a/.local/bin/statusbar/sb-forecast +++ b/.local/bin/statusbar/sb-forecast @@ -7,7 +7,7 @@ url="${WTTRURL:-wttr.in}" weatherreport="${XDG_CACHE_HOME:-$HOME/.cache}/weatherreport" # Get a weather report from 'wttr.in' and save it locally. -getforecast() { curl -sf "$url/$LOCATION" > "$weatherreport" || exit 1; } +getforecast() { curl --retry 5 -sfm 10 "$url/$LOCATION" > "$weatherreport" || exit 1; } # Forecast should be updated only once a day. checkforecast() { diff --git a/.local/bin/statusbar/sb-iplocate b/.local/bin/statusbar/sb-iplocate index 46e69507..ca38bf36 100755 --- a/.local/bin/statusbar/sb-iplocate +++ b/.local/bin/statusbar/sb-iplocate @@ -5,7 +5,11 @@ # # https://www.maketecheasier.com/ip-address-geolocation-lookups-linux/ -ifinstalled "geoip" || exit +ifinstalled "geoip" || exit 1 + ipfile="$XDG_RUNTIME_DIR/iplocate" -addr=$(cat "$ipfile") && rm "$ipfile" || { ( curl -s ifconfig.me > "$ipfile" && pkill -RTMIN+"${1:-27}" "${STATUSBAR:-dwmblocks}") & echo; exit; } -grep "flag: " "${XDG_DATA_HOME:-$HOME/.local/share}/larbs/emoji" | grep "$(geoiplookup "$addr" | sed 's/.*, //')" | sed "s/flag: //;s/;.*//" +addr=$(cat "$ipfile" 2>/dev/null) && addr=$(geoiplookup "$addr" 2>/dev/null) && rm "$ipfile" || { ( curl --retry 5 -sfm 10 ifconfig.me > "$ipfile" && pkill -RTMIN+"${1:-27}" "${STATUSBAR:-dwmblocks}" ) & echo; exit; } +name="${addr##*, }" +flag="$(grep "flag: $name" "${XDG_DATA_HOME:-$HOME/.local/share}/larbs/emoji")" +flag="${flag%% *}" +printf "%s %s\\n" "$flag" "$name" diff --git a/.local/bin/statusbar/sb-moonphase b/.local/bin/statusbar/sb-moonphase index 635b8608..d369beb3 100755 --- a/.local/bin/statusbar/sb-moonphase +++ b/.local/bin/statusbar/sb-moonphase @@ -5,7 +5,7 @@ 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" && pkill -RTMIN+"${1:-17}" "${STATUSBAR:-dwmblocks}" ) & echo; exit; } + { ( curl --retry 5 -sfm 10 "wttr.in/?format=%m" > "$moonfile" && pkill -RTMIN+"${1:-17}" "${STATUSBAR:-dwmblocks}" ) & echo; exit; } icon="$(cat "$moonfile")" diff --git a/.local/bin/statusbar/sb-price b/.local/bin/statusbar/sb-price index e52dc56b..d9541c2e 100755 --- a/.local/bin/statusbar/sb-price +++ b/.local/bin/statusbar/sb-price @@ -1,27 +1,34 @@ #!/bin/sh # Usage: -# price -# price bat "Basic Attention Token" 🦁 +# price +# price bat-btc "Basic Attention Token" 🦁 24 +# This will give the price of BAT denominated in BTC and will update on +# signal 24. # When the name of the currency is multi-word, put it in quotes. -[ -z "$3" ] && exit 1 - -# handle optional parameters in $4 and/or $5 -echo "$4" | grep -q '^[0-9]' && - currency='usd' && sig=$4 || - { currency="${4:-usd}"; sig=$5; } +[ -z "$1" ] && exit 1 url="${CRYPTOURL:-rate.sx}" +target="${1%%-*}" +denom="${1##*-}" +name="${2:-$1}" +icon="${3:-💰}" +case "$denom" in + "$target"|usd) denom="usd"; symb="$" ;; + gbp) symb="£" ;; + eur) symb="€" ;; + btc) symb="" ;; +esac interval="@14d" # History contained in chart preceded by '@' (7d = 7 days) dir="${XDG_CACHE_HOME:-$HOME/.cache}/crypto-prices" -pricefile="$dir/$1-$currency" -chartfile="$dir/$1-$currency-chart" +pricefile="$dir/$target-$denom" +chartfile="$dir/$target-$denom-chart" filestat="$(stat -c %x "$pricefile" 2>/dev/null)" [ -d "$dir" ] || mkdir -p "$dir" -updateprice() { curl -sf $currency.$url/{1$1,$1$interval} --output "$pricefile" --output "$chartfile" || +updateprice() { curl --retry 5 -sfm 10 $denom.$url/{1$target,$target$interval} --output "$pricefile" --output "$chartfile" || rm -f "$pricefile" "$chartfile" ;} [ "${filestat%% *}" != "$(date '+%Y-%m-%d')" ] && @@ -29,9 +36,9 @@ updateprice() { curl -sf $currency.$url/{1$1,$1$interval} --output "$pricefile" case $BLOCK_BUTTON in 1) setsid "$TERMINAL" -e less -Srf "$chartfile" ;; - 2) notify-send -u low "$3 Updating..." "Updating $2 price..." ; updateme="1" ; showupdate="1" ;; + 2) notify-send -u low "$icon Updating..." "Updating $name price..." ; updateme="1" ; showupdate="1" ;; 3) uptime="$(date -d "$filestat" '+%D at %T' | sed "s|$(date '+%D')|Today|")" - notify-send "$3 $2 module" "\- Exact price: \$$(cat "$pricefile") + notify-send "$icon $name module" "\- Exact price: \$$(cat "$pricefile") - Left click for chart of changes. - Middle click to update. - Shows 🔃 if updating prices. @@ -42,18 +49,11 @@ esac [ -n "$updateme" ] && if [ -n "$showupdate" ]; then - updateprice "$1" && notify-send "$3 Update complete." "$2 price is now \$$(cat "$pricefile")" + updateprice && notify-send "$icon Update complete." "$name price is now \$$(cat "$pricefile")" else - [ -n "$sig" ] && - { ( updateprice "$1" && pkill -RTMIN+"$sig" "${STATUSBAR:-dwmblocks}" ) & echo; exit; } || - updateprice "$1" + [ -n "$4" ] && + { ( updateprice && pkill -RTMIN+"$4" "${STATUSBAR:-dwmblocks}" ) & echo; exit; } || + updateprice fi -case "$currency" in - usd) symb="$" ;; - gbp) symb="£" ;; - eur) symb="€" ;; - btc) symb="" ;; -esac - -[ -f "$pricefile" ] && printf "$3$symb%0.2f" "$(cat "$pricefile")" +[ -f "$pricefile" ] && printf "%s%s%0.2f" "$icon" "$symb" "$(cat "$pricefile")" From b7dc644e1adf1dd07330c57de052ad95bfb48574 Mon Sep 17 00:00:00 2001 From: appeasementPolitik <108810900+appeasementPolitik@users.noreply.github.com> Date: Sun, 23 Apr 2023 15:02:32 +0000 Subject: [PATCH 05/11] Re-add fail-early to sb-price --- .local/bin/statusbar/sb-price | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.local/bin/statusbar/sb-price b/.local/bin/statusbar/sb-price index d9541c2e..082c35ec 100755 --- a/.local/bin/statusbar/sb-price +++ b/.local/bin/statusbar/sb-price @@ -28,7 +28,7 @@ filestat="$(stat -c %x "$pricefile" 2>/dev/null)" [ -d "$dir" ] || mkdir -p "$dir" -updateprice() { curl --retry 5 -sfm 10 $denom.$url/{1$target,$target$interval} --output "$pricefile" --output "$chartfile" || +updateprice() { curl --retry 5 -sfm 10 --fail-early $denom.$url/{1$target,$target$interval} --output "$pricefile" --output "$chartfile" || rm -f "$pricefile" "$chartfile" ;} [ "${filestat%% *}" != "$(date '+%Y-%m-%d')" ] && From de863bf0f015fb408d5b0f09d1673593f05b824d Mon Sep 17 00:00:00 2001 From: appeasementPolitik <108810900+appeasementPolitik@users.noreply.github.com> Date: Wed, 16 Aug 2023 10:56:33 +0000 Subject: [PATCH 06/11] Make the retry logic better + other changes --- .local/bin/statusbar/sb-forecast | 11 ++++++++--- .local/bin/statusbar/sb-iplocate | 7 ++++++- .local/bin/statusbar/sb-moonphase | 6 +++++- .local/bin/statusbar/sb-price | 9 ++++++--- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/.local/bin/statusbar/sb-forecast b/.local/bin/statusbar/sb-forecast index ba249a66..bfd2f64d 100755 --- a/.local/bin/statusbar/sb-forecast +++ b/.local/bin/statusbar/sb-forecast @@ -7,7 +7,7 @@ url="${WTTRURL:-wttr.in}" weatherreport="${XDG_CACHE_HOME:-$HOME/.cache}/weatherreport" # Get a weather report from 'wttr.in' and save it locally. -getforecast() { curl --retry 5 -sfm 10 "$url/$LOCATION" > "$weatherreport" || exit 1; } +getforecast() { curl -sf "$url/$LOCATION" > "$weatherreport"; } # Forecast should be updated only once a day. checkforecast() { @@ -38,7 +38,7 @@ showweather() { } case $BLOCK_BUTTON in - 1) setsid -f "$TERMINAL" -e less -Srf "$weatherreport" ;; + 1) setsid -f "$TERMINAL" -e less -Sf "$weatherreport" ;; 2) getforecast && showweather ;; 3) notify-send "🌈 Weather module" "\- Left click for full forecast. - Middle click to update forecast. @@ -48,4 +48,9 @@ case $BLOCK_BUTTON in 6) "$TERMINAL" -e "$EDITOR" "$0" ;; esac -checkforecast && showweather || { ( getforecast && pkill -RTMIN+"${1:-5}" "${STATUSBAR:-dwmblocks}") & echo; } +checkforecast && showweather || + { [ -z "$(pgrep 'sb-forecast' | tail -n +3)" ] && + ( until { [ "$(cat /sys/class/net/w*/operstate)" = 'up' ] || [ "$(cat /sys/class/net/e*/operstate)" = 'up' ]; } && + getforecast; do sleep 60; done && + pkill -RTMIN+"${1:-5}" "${STATUSBAR:-dwmblocks}" ) & + echo; } diff --git a/.local/bin/statusbar/sb-iplocate b/.local/bin/statusbar/sb-iplocate index ca38bf36..d075ba40 100755 --- a/.local/bin/statusbar/sb-iplocate +++ b/.local/bin/statusbar/sb-iplocate @@ -8,7 +8,12 @@ ifinstalled "geoip" || exit 1 ipfile="$XDG_RUNTIME_DIR/iplocate" -addr=$(cat "$ipfile" 2>/dev/null) && addr=$(geoiplookup "$addr" 2>/dev/null) && rm "$ipfile" || { ( curl --retry 5 -sfm 10 ifconfig.me > "$ipfile" && pkill -RTMIN+"${1:-27}" "${STATUSBAR:-dwmblocks}" ) & echo; exit; } +addr=$(cat "$ipfile" 2>/dev/null) && addr=$(geoiplookup "$addr" 2>/dev/null) && rm "$ipfile" || + { [ -z "$(pgrep 'sb-iplocate' | tail -n +3)" ] && + ( until { [ "$(cat /sys/class/net/w*/operstate)" = 'up' ] || [ "$(cat /sys/class/net/e*/operstate)" = 'up' ]; } && + curl -sf ifconfig.me > "$ipfile"; do sleep 60; done && + pkill -RTMIN+"${1:-27}" "${STATUSBAR:-dwmblocks}" ) & + echo; exit; } name="${addr##*, }" flag="$(grep "flag: $name" "${XDG_DATA_HOME:-$HOME/.local/share}/larbs/emoji")" flag="${flag%% *}" diff --git a/.local/bin/statusbar/sb-moonphase b/.local/bin/statusbar/sb-moonphase index d369beb3..ba75c7c0 100755 --- a/.local/bin/statusbar/sb-moonphase +++ b/.local/bin/statusbar/sb-moonphase @@ -5,7 +5,11 @@ 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 --retry 5 -sfm 10 "wttr.in/?format=%m" > "$moonfile" && pkill -RTMIN+"${1:-17}" "${STATUSBAR:-dwmblocks}" ) & echo; exit; } + { [ -z "$(pgrep 'sb-moonphase' | tail -n +3)" ] && + ( until { [ "$(cat /sys/class/net/w*/operstate)" = 'up' ] || [ "$(cat /sys/class/net/e*/operstate)" = 'up' ]; } && + curl -sf "wttr.in/?format=%m" > "$moonfile"; do sleep 60; done && + pkill -RTMIN+"${1:-17}" "${STATUSBAR:-dwmblocks}" ) & + echo; exit; } icon="$(cat "$moonfile")" diff --git a/.local/bin/statusbar/sb-price b/.local/bin/statusbar/sb-price index 082c35ec..fea69b6d 100755 --- a/.local/bin/statusbar/sb-price +++ b/.local/bin/statusbar/sb-price @@ -28,8 +28,7 @@ filestat="$(stat -c %x "$pricefile" 2>/dev/null)" [ -d "$dir" ] || mkdir -p "$dir" -updateprice() { curl --retry 5 -sfm 10 --fail-early $denom.$url/{1$target,$target$interval} --output "$pricefile" --output "$chartfile" || - rm -f "$pricefile" "$chartfile" ;} +updateprice() { curl -sf --fail-early $denom.$url/{1$target,$target$interval} --output "$pricefile" --output "$chartfile"; } [ "${filestat%% *}" != "$(date '+%Y-%m-%d')" ] && updateme="1" @@ -52,7 +51,11 @@ esac updateprice && notify-send "$icon Update complete." "$name price is now \$$(cat "$pricefile")" else [ -n "$4" ] && - { ( updateprice && pkill -RTMIN+"$4" "${STATUSBAR:-dwmblocks}" ) & echo; exit; } || + { [ -z "$(pgrep 'sb-price' | tail -n +3)" ] && + ( until { [ "$(cat /sys/class/net/w*/operstate)" = 'up' ] || [ "$(cat /sys/class/net/e*/operstate)" = 'up' ]; } && + updateprice; do sleep 60; done && + pkill -RTMIN+"$4" "${STATUSBAR:-dwmblocks}" ) & + echo; exit; } || updateprice fi From 36d40adb8df2809767d8c0447b9f4d3d62200d1d Mon Sep 17 00:00:00 2001 From: appeasementPolitik <108810900+appeasementPolitik@users.noreply.github.com> Date: Wed, 16 Aug 2023 13:32:44 +0000 Subject: [PATCH 07/11] Only redirect non-empty output: for when services are down --- .local/bin/statusbar/sb-forecast | 2 +- .local/bin/statusbar/sb-iplocate | 2 +- .local/bin/statusbar/sb-moonphase | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.local/bin/statusbar/sb-forecast b/.local/bin/statusbar/sb-forecast index bfd2f64d..2920f914 100755 --- a/.local/bin/statusbar/sb-forecast +++ b/.local/bin/statusbar/sb-forecast @@ -7,7 +7,7 @@ url="${WTTRURL:-wttr.in}" weatherreport="${XDG_CACHE_HOME:-$HOME/.cache}/weatherreport" # Get a weather report from 'wttr.in' and save it locally. -getforecast() { curl -sf "$url/$LOCATION" > "$weatherreport"; } +getforecast() { curl -sf "$url/$LOCATION" --output "$weatherreport"; } # Forecast should be updated only once a day. checkforecast() { diff --git a/.local/bin/statusbar/sb-iplocate b/.local/bin/statusbar/sb-iplocate index d075ba40..8cf17421 100755 --- a/.local/bin/statusbar/sb-iplocate +++ b/.local/bin/statusbar/sb-iplocate @@ -11,7 +11,7 @@ ipfile="$XDG_RUNTIME_DIR/iplocate" addr=$(cat "$ipfile" 2>/dev/null) && addr=$(geoiplookup "$addr" 2>/dev/null) && rm "$ipfile" || { [ -z "$(pgrep 'sb-iplocate' | tail -n +3)" ] && ( until { [ "$(cat /sys/class/net/w*/operstate)" = 'up' ] || [ "$(cat /sys/class/net/e*/operstate)" = 'up' ]; } && - curl -sf ifconfig.me > "$ipfile"; do sleep 60; done && + curl -sf ifconfig.me --output "$ipfile"; do sleep 60; done && pkill -RTMIN+"${1:-27}" "${STATUSBAR:-dwmblocks}" ) & echo; exit; } name="${addr##*, }" diff --git a/.local/bin/statusbar/sb-moonphase b/.local/bin/statusbar/sb-moonphase index ba75c7c0..242a19cf 100755 --- a/.local/bin/statusbar/sb-moonphase +++ b/.local/bin/statusbar/sb-moonphase @@ -7,7 +7,7 @@ moonfile="${XDG_DATA_HOME:-$HOME/.local/share}/moonphase" [ -s "$moonfile" ] && [ "$(stat -c %y "$moonfile" 2>/dev/null | cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] || { [ -z "$(pgrep 'sb-moonphase' | tail -n +3)" ] && ( until { [ "$(cat /sys/class/net/w*/operstate)" = 'up' ] || [ "$(cat /sys/class/net/e*/operstate)" = 'up' ]; } && - curl -sf "wttr.in/?format=%m" > "$moonfile"; do sleep 60; done && + curl -sf "wttr.in/?format=%m" --output "$moonfile"; do sleep 60; done && pkill -RTMIN+"${1:-17}" "${STATUSBAR:-dwmblocks}" ) & echo; exit; } From b0dbb1d1f64480fd6b62f7a03923350228467cfa Mon Sep 17 00:00:00 2001 From: appeasementPolitik <108810900+appeasementPolitik@users.noreply.github.com> Date: Fri, 18 Aug 2023 14:49:50 +0000 Subject: [PATCH 08/11] Also change modification time --- .local/bin/statusbar/sb-forecast | 2 +- .local/bin/statusbar/sb-moonphase | 2 +- .local/bin/statusbar/sb-price | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.local/bin/statusbar/sb-forecast b/.local/bin/statusbar/sb-forecast index 2920f914..fd224705 100755 --- a/.local/bin/statusbar/sb-forecast +++ b/.local/bin/statusbar/sb-forecast @@ -7,7 +7,7 @@ url="${WTTRURL:-wttr.in}" weatherreport="${XDG_CACHE_HOME:-$HOME/.cache}/weatherreport" # Get a weather report from 'wttr.in' and save it locally. -getforecast() { curl -sf "$url/$LOCATION" --output "$weatherreport"; } +getforecast() { curl -sf "$url/$LOCATION" --output "$weatherreport" && touch "$weatherreport"; } # Forecast should be updated only once a day. checkforecast() { diff --git a/.local/bin/statusbar/sb-moonphase b/.local/bin/statusbar/sb-moonphase index 242a19cf..49201130 100755 --- a/.local/bin/statusbar/sb-moonphase +++ b/.local/bin/statusbar/sb-moonphase @@ -7,7 +7,7 @@ moonfile="${XDG_DATA_HOME:-$HOME/.local/share}/moonphase" [ -s "$moonfile" ] && [ "$(stat -c %y "$moonfile" 2>/dev/null | cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] || { [ -z "$(pgrep 'sb-moonphase' | tail -n +3)" ] && ( until { [ "$(cat /sys/class/net/w*/operstate)" = 'up' ] || [ "$(cat /sys/class/net/e*/operstate)" = 'up' ]; } && - curl -sf "wttr.in/?format=%m" --output "$moonfile"; do sleep 60; done && + curl -sf "wttr.in/?format=%m" --output "$moonfile" && touch "$moonfile"; do sleep 60; done && pkill -RTMIN+"${1:-17}" "${STATUSBAR:-dwmblocks}" ) & echo; exit; } diff --git a/.local/bin/statusbar/sb-price b/.local/bin/statusbar/sb-price index fea69b6d..94d25b9a 100755 --- a/.local/bin/statusbar/sb-price +++ b/.local/bin/statusbar/sb-price @@ -28,7 +28,7 @@ filestat="$(stat -c %x "$pricefile" 2>/dev/null)" [ -d "$dir" ] || mkdir -p "$dir" -updateprice() { curl -sf --fail-early $denom.$url/{1$target,$target$interval} --output "$pricefile" --output "$chartfile"; } +updateprice() { curl -sf --fail-early $denom.$url/{1$target,$target$interval} --output "$pricefile" --output "$chartfile" && touch "$pricefile" "$chartfile"; } [ "${filestat%% *}" != "$(date '+%Y-%m-%d')" ] && updateme="1" From 92d3560888279fad9df63a4295b55b01522112cd Mon Sep 17 00:00:00 2001 From: appeasementPolitik <108810900+appeasementPolitik@users.noreply.github.com> Date: Fri, 18 Aug 2023 21:21:44 +0000 Subject: [PATCH 09/11] Robustness not needed anymore because of curl's --output, no more empty files --- .local/bin/statusbar/sb-forecast | 2 +- .local/bin/statusbar/sb-moonphase | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.local/bin/statusbar/sb-forecast b/.local/bin/statusbar/sb-forecast index fd224705..91592ca8 100755 --- a/.local/bin/statusbar/sb-forecast +++ b/.local/bin/statusbar/sb-forecast @@ -11,7 +11,7 @@ getforecast() { curl -sf "$url/$LOCATION" --output "$weatherreport" && touch "$w # Forecast should be updated only once a day. checkforecast() { - [ -s "$weatherreport" ] && [ "$(stat -c %y "$weatherreport" 2>/dev/null | + [ "$(stat -c %y "$weatherreport" 2>/dev/null | cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] } diff --git a/.local/bin/statusbar/sb-moonphase b/.local/bin/statusbar/sb-moonphase index 49201130..26e3f13f 100755 --- a/.local/bin/statusbar/sb-moonphase +++ b/.local/bin/statusbar/sb-moonphase @@ -4,7 +4,7 @@ moonfile="${XDG_DATA_HOME:-$HOME/.local/share}/moonphase" -[ -s "$moonfile" ] && [ "$(stat -c %y "$moonfile" 2>/dev/null | cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] || +[ "$(stat -c %y "$moonfile" 2>/dev/null | cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] || { [ -z "$(pgrep 'sb-moonphase' | tail -n +3)" ] && ( until { [ "$(cat /sys/class/net/w*/operstate)" = 'up' ] || [ "$(cat /sys/class/net/e*/operstate)" = 'up' ]; } && curl -sf "wttr.in/?format=%m" --output "$moonfile" && touch "$moonfile"; do sleep 60; done && From 1500ec504e44c3b2a3367c6bb54c1be865f7416e Mon Sep 17 00:00:00 2001 From: appeasementPolitik <108810900+appeasementPolitik@users.noreply.github.com> Date: Tue, 3 Oct 2023 21:23:15 +0000 Subject: [PATCH 10/11] Use actual locks instead of pgrep --- .local/bin/statusbar/sb-forecast | 4 ++-- .local/bin/statusbar/sb-iplocate | 6 +++--- .local/bin/statusbar/sb-moonphase | 4 ++-- .local/bin/statusbar/sb-price | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.local/bin/statusbar/sb-forecast b/.local/bin/statusbar/sb-forecast index 91592ca8..07742dc7 100755 --- a/.local/bin/statusbar/sb-forecast +++ b/.local/bin/statusbar/sb-forecast @@ -49,8 +49,8 @@ case $BLOCK_BUTTON in esac checkforecast && showweather || - { [ -z "$(pgrep 'sb-forecast' | tail -n +3)" ] && + ( flock -n 9 && ( until { [ "$(cat /sys/class/net/w*/operstate)" = 'up' ] || [ "$(cat /sys/class/net/e*/operstate)" = 'up' ]; } && getforecast; do sleep 60; done && pkill -RTMIN+"${1:-5}" "${STATUSBAR:-dwmblocks}" ) & - echo; } + echo ) 9>/tmp/sb-forecast.lock diff --git a/.local/bin/statusbar/sb-iplocate b/.local/bin/statusbar/sb-iplocate index 8cf17421..eaf1941f 100755 --- a/.local/bin/statusbar/sb-iplocate +++ b/.local/bin/statusbar/sb-iplocate @@ -9,11 +9,11 @@ ifinstalled "geoip" || exit 1 ipfile="$XDG_RUNTIME_DIR/iplocate" addr=$(cat "$ipfile" 2>/dev/null) && addr=$(geoiplookup "$addr" 2>/dev/null) && rm "$ipfile" || - { [ -z "$(pgrep 'sb-iplocate' | tail -n +3)" ] && + ( flock -n 9 && ( until { [ "$(cat /sys/class/net/w*/operstate)" = 'up' ] || [ "$(cat /sys/class/net/e*/operstate)" = 'up' ]; } && - curl -sf ifconfig.me --output "$ipfile"; do sleep 60; done && + curl -sf api.ipify.org --output "$ipfile"; do sleep 60; done && pkill -RTMIN+"${1:-27}" "${STATUSBAR:-dwmblocks}" ) & - echo; exit; } + echo; exit ) 9>/tmp/sb-iplocate.lock name="${addr##*, }" flag="$(grep "flag: $name" "${XDG_DATA_HOME:-$HOME/.local/share}/larbs/emoji")" flag="${flag%% *}" diff --git a/.local/bin/statusbar/sb-moonphase b/.local/bin/statusbar/sb-moonphase index 26e3f13f..ec059885 100755 --- a/.local/bin/statusbar/sb-moonphase +++ b/.local/bin/statusbar/sb-moonphase @@ -5,11 +5,11 @@ moonfile="${XDG_DATA_HOME:-$HOME/.local/share}/moonphase" [ "$(stat -c %y "$moonfile" 2>/dev/null | cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] || - { [ -z "$(pgrep 'sb-moonphase' | tail -n +3)" ] && + ( flock -n 9 && ( until { [ "$(cat /sys/class/net/w*/operstate)" = 'up' ] || [ "$(cat /sys/class/net/e*/operstate)" = 'up' ]; } && curl -sf "wttr.in/?format=%m" --output "$moonfile" && touch "$moonfile"; do sleep 60; done && pkill -RTMIN+"${1:-17}" "${STATUSBAR:-dwmblocks}" ) & - echo; exit; } + echo; exit ) 9>/tmp/sb-moonphase.lock icon="$(cat "$moonfile")" diff --git a/.local/bin/statusbar/sb-price b/.local/bin/statusbar/sb-price index 94d25b9a..ce266c3a 100755 --- a/.local/bin/statusbar/sb-price +++ b/.local/bin/statusbar/sb-price @@ -51,11 +51,11 @@ esac updateprice && notify-send "$icon Update complete." "$name price is now \$$(cat "$pricefile")" else [ -n "$4" ] && - { [ -z "$(pgrep 'sb-price' | tail -n +3)" ] && + ( flock -n 9 && ( until { [ "$(cat /sys/class/net/w*/operstate)" = 'up' ] || [ "$(cat /sys/class/net/e*/operstate)" = 'up' ]; } && updateprice; do sleep 60; done && pkill -RTMIN+"$4" "${STATUSBAR:-dwmblocks}" ) & - echo; exit; } || + echo; exit ) 9>/tmp/sb-price.lock || updateprice fi From 0afc70a07c69b2a6fb1ab153a7087a0776e5fa8f Mon Sep 17 00:00:00 2001 From: appeasementPolitik <108810900+appeasementPolitik@users.noreply.github.com> Date: Sat, 25 Nov 2023 09:13:56 +0000 Subject: [PATCH 11/11] Change to more suitable lock file location for user programs --- .local/bin/statusbar/sb-forecast | 2 +- .local/bin/statusbar/sb-iplocate | 2 +- .local/bin/statusbar/sb-moonphase | 2 +- .local/bin/statusbar/sb-price | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.local/bin/statusbar/sb-forecast b/.local/bin/statusbar/sb-forecast index 07742dc7..028c20f5 100755 --- a/.local/bin/statusbar/sb-forecast +++ b/.local/bin/statusbar/sb-forecast @@ -53,4 +53,4 @@ checkforecast && showweather || ( until { [ "$(cat /sys/class/net/w*/operstate)" = 'up' ] || [ "$(cat /sys/class/net/e*/operstate)" = 'up' ]; } && getforecast; do sleep 60; done && pkill -RTMIN+"${1:-5}" "${STATUSBAR:-dwmblocks}" ) & - echo ) 9>/tmp/sb-forecast.lock + echo ) 9>"${XDG_RUNTIME_DIR}/sb-forecast.lock" diff --git a/.local/bin/statusbar/sb-iplocate b/.local/bin/statusbar/sb-iplocate index eaf1941f..7911b503 100755 --- a/.local/bin/statusbar/sb-iplocate +++ b/.local/bin/statusbar/sb-iplocate @@ -13,7 +13,7 @@ addr=$(cat "$ipfile" 2>/dev/null) && addr=$(geoiplookup "$addr" 2>/dev/null) && ( until { [ "$(cat /sys/class/net/w*/operstate)" = 'up' ] || [ "$(cat /sys/class/net/e*/operstate)" = 'up' ]; } && curl -sf api.ipify.org --output "$ipfile"; do sleep 60; done && pkill -RTMIN+"${1:-27}" "${STATUSBAR:-dwmblocks}" ) & - echo; exit ) 9>/tmp/sb-iplocate.lock + echo; exit ) 9>"${XDG_RUNTIME_DIR}/sb-iplocate.lock" name="${addr##*, }" flag="$(grep "flag: $name" "${XDG_DATA_HOME:-$HOME/.local/share}/larbs/emoji")" flag="${flag%% *}" diff --git a/.local/bin/statusbar/sb-moonphase b/.local/bin/statusbar/sb-moonphase index ec059885..3d77bf9e 100755 --- a/.local/bin/statusbar/sb-moonphase +++ b/.local/bin/statusbar/sb-moonphase @@ -9,7 +9,7 @@ moonfile="${XDG_DATA_HOME:-$HOME/.local/share}/moonphase" ( until { [ "$(cat /sys/class/net/w*/operstate)" = 'up' ] || [ "$(cat /sys/class/net/e*/operstate)" = 'up' ]; } && curl -sf "wttr.in/?format=%m" --output "$moonfile" && touch "$moonfile"; do sleep 60; done && pkill -RTMIN+"${1:-17}" "${STATUSBAR:-dwmblocks}" ) & - echo; exit ) 9>/tmp/sb-moonphase.lock + echo; exit ) 9>"${XDG_RUNTIME_DIR}/sb-moonphase.lock" icon="$(cat "$moonfile")" diff --git a/.local/bin/statusbar/sb-price b/.local/bin/statusbar/sb-price index ce266c3a..29bd497f 100755 --- a/.local/bin/statusbar/sb-price +++ b/.local/bin/statusbar/sb-price @@ -55,7 +55,7 @@ esac ( until { [ "$(cat /sys/class/net/w*/operstate)" = 'up' ] || [ "$(cat /sys/class/net/e*/operstate)" = 'up' ]; } && updateprice; do sleep 60; done && pkill -RTMIN+"$4" "${STATUSBAR:-dwmblocks}" ) & - echo; exit ) 9>/tmp/sb-price.lock || + echo; exit ) 9>"${XDG_RUNTIME_DIR}/sb-price.lock" || updateprice fi