From e12062b85d42e5a76844b78fb4382e2bc277539a Mon Sep 17 00:00:00 2001 From: TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> Date: Tue, 30 Jun 2026 13:23:58 +0900 Subject: deleted statusbar/sb-iplocate, modified statusbar/sb-price --- ar/.local/bin/statusbar/sb-iplocate | 15 -------- ar/.local/bin/statusbar/sb-price | 73 ++++++++++++++++++++++++------------- 2 files changed, 48 insertions(+), 40 deletions(-) delete mode 100755 ar/.local/bin/statusbar/sb-iplocate (limited to 'ar/.local') diff --git a/ar/.local/bin/statusbar/sb-iplocate b/ar/.local/bin/statusbar/sb-iplocate deleted file mode 100755 index d7a9349..0000000 --- a/ar/.local/bin/statusbar/sb-iplocate +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh - -# Gets your public ip address checks which country you are in and -# displays that information in the statusbar -# -# https://www.maketecheasier.com/ip-address-geolocation-lookups-linux/ - -set -e - -ifinstalled "geoip" -addr="$(geoiplookup "$(curl -sfm 1 ifconfig.me 2>/dev/null)")" -name="${addr##*, }" -flag="$(grep "flag: $name" "${XDG_DATA_HOME:-${HOME}/.local/share}/thesiah/chars/emoji")" -flag="${flag%% *}" -printf "%s %s\\n" "$flag" "$name" diff --git a/ar/.local/bin/statusbar/sb-price b/ar/.local/bin/statusbar/sb-price index 70703f8..5323ef1 100755 --- a/ar/.local/bin/statusbar/sb-price +++ b/ar/.local/bin/statusbar/sb-price @@ -2,9 +2,9 @@ # Usage: # price -# price bat-btc "Basic Attention Token" 🦁 25 +# price bat-btc "Basic Attention Token" 🦁 21 # This will give the price of BAT denominated in BTC and will update on -# signal 25. +# signal 21. # When the name of the currency is multi-word, put it in quotes. [ -z "$1" ] && exit 1 @@ -23,21 +23,27 @@ gbp) symb="£" ;; eur) symb="€" ;; btc) symb="" ;; esac -interval="@1d" # History contained in chart preceded by '@' (7d = 7 days) -dir="${XDG_CACHE_HOME:-${HOME}/.cache}/crypto-prices" +interval="@14d" # History contained in chart preceded by '@' (7d = 7 days) +dir="${XDG_CACHE_HOME:-$HOME/.cache}/crypto-prices" 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 \ - --fail-early "${denom}.${url}/1${target}" "${denom}.${url}/${target}${interval}" \ - --output "$pricefile" --output "$chartfile" || - rm -f "$pricefile" "$chartfile"; } +checkprice() { + [ "$(stat -c %y "$pricefile" 2>/dev/null | + cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] +} -[ "${filestat%% *}" != "$(date '+%Y-%m-%d')" ] && - updateme="1" +updateprice() { + { grep -q -m1 '^up$' /sys/class/net/w*/operstate || grep -q -m1 '^up$' /sys/class/net/e*/operstate; } && + curl -sf \ + --fail-early "${denom}.${url}/1${target}" "${denom}.${url}/${target}${interval}" \ + --output "$pricefile" --output "$chartfile" && + touch "$pricefile" "$chartfile" +} + +checkprice || updateme="1" case $BLOCK_BUTTON in 1) setsid "$TERMINAL" -e less -Srf "$chartfile" ;; @@ -47,25 +53,42 @@ case $BLOCK_BUTTON in showupdate="1" ;; 3) - uptime="$(date -d "$filestat" '+%D at %T' | sed "s|$(date '+%D')|Today|")" + uptime="$(date -d "$(stat -c %x "$pricefile" 2>/dev/null)" '+%D at %T' | sed "s|$(date '+%D')|Today|")" notify-send "$icon $name module" "\- Exact price: \$$(cat "$pricefile") -- Left click for chart of changes -- Middle click to update -- Shows 🔃 if updating prices +- Left click for chart of changes. +- Middle click to update. +- Shows 🔃 if updating prices. - Last updated: -$uptime" + $uptime" ;; 6) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;; esac [ -n "$updateme" ] && - updateprice "$target" && - [ -n "$showupdate" ] && - notify-send "$icon Update complete" "$name price is now -\$$(cat "$pricefile")" + if [ -n "$showupdate" ]; then + updateprice && notify-send "$icon Update complete." "$name price is now \$$(cat "$pricefile")" + else + # shellcheck disable=SC2015 + [ -n "$4" ] && + ( + flock -n 9 && + ( + tries=0 + while [ $tries -ne 100 ]; do + updateprice && break || + { + tries=$((tries + 1)) + sleep .1 + } + done + ! checkprice && + until updateprice; do sleep 60; done + pkill -RTMIN+"$4" "${STATUSBAR:-dwmblocks}" + ) & + echo + exit + ) 9>"${XDG_RUNTIME_DIR}/sb-price.lock" || + updateprice + fi -[ -f "$pricefile" ] && { - price=$(cat "$pricefile") - formatted_price=$(printf "%0.2f" "$price" | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta') - printf "%s%s%s" "$icon" "$symb" "$formatted_price" -} +[ -f "$pricefile" ] && printf "%s%s%0.2f" "$icon" "$symb" "$(cat "$pricefile")" -- cgit v1.2.3