summaryrefslogtreecommitdiffstats
path: root/.local/bin/statusbar/sb-price
diff options
context:
space:
mode:
authorLuke Smith <luke@lukesmith.xyz>2023-04-20 08:48:34 -0400
committerLuke Smith <luke@lukesmith.xyz>2023-04-20 08:48:34 -0400
commit65378ab9443401e0e895d50ad894d66ba4c3ff31 (patch)
tree95717aa4816453ce3c4fd5b58656a083ee50810b /.local/bin/statusbar/sb-price
parentb719590427681e977b2a13e8490971e1e1b166b8 (diff)
downloadeibhear-65378ab9443401e0e895d50ad894d66ba4c3ff31.tar.gz
eibhear-65378ab9443401e0e895d50ad894d66ba4c3ff31.tar.zst
eibhear-65378ab9443401e0e895d50ad894d66ba4c3ff31.zip
sb-price improvements
Diffstat (limited to '.local/bin/statusbar/sb-price')
-rwxr-xr-x.local/bin/statusbar/sb-price43
1 files changed, 23 insertions, 20 deletions
diff --git a/.local/bin/statusbar/sb-price b/.local/bin/statusbar/sb-price
index 9dc2d52..f95c815 100755
--- a/.local/bin/statusbar/sb-price
+++ b/.local/bin/statusbar/sb-price
@@ -1,24 +1,34 @@
#!/bin/sh
# Usage:
-# price <url> <Name of currency> <icon> <Price to show in>
-# price bat "Basic Attention Token" 🦁
+# price <currency-base currency> <name of currency> <icon> <signal>
+# 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
+[ -z "$1" ] && exit 1
-# use $4 as currency, if not passed in use "usd" as default
url="${CRYPTOURL:-rate.sx}"
-currency="${4:-usd}"
+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 -m 1 --fail-early $currency.$url/{1$1,$1$interval} --output "$pricefile" --output "$chartfile" ||
+updateprice() { curl -sf -m 1 --fail-early $denom.$url/{1$target,$target$interval} --output "$pricefile" --output "$chartfile" ||
rm -f "$pricefile" "$chartfile" ;}
[ "${filestat%% *}" != "$(date '+%Y-%m-%d')" ] &&
@@ -26,9 +36,9 @@ updateprice() { curl -sf -m 1 --fail-early $currency.$url/{1$1,$1$interval} --ou
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" "\- <b>Exact price: \$$(cat "$pricefile")</b>
+ notify-send "$icon $name module" "\- <b>Exact price: \$$(cat "$pricefile")</b>
- Left click for chart of changes.
- Middle click to update.
- Shows 🔃 if updating prices.
@@ -38,16 +48,9 @@ case $BLOCK_BUTTON in
esac
[ -n "$updateme" ] &&
- updateprice "$1" &&
+ updateprice "$target" &&
[ -n "$showupdate" ] &&
- notify-send "$3 Update complete." "$2 price is now
+ notify-send "$icon Update complete." "$name price is now
\$$(cat "$pricefile")"
-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")"