diff options
Diffstat (limited to '.local/bin/statusbar/sb-price')
| -rwxr-xr-x | .local/bin/statusbar/sb-price | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/.local/bin/statusbar/sb-price b/.local/bin/statusbar/sb-price index 35b072f..42c84c1 100755 --- a/.local/bin/statusbar/sb-price +++ b/.local/bin/statusbar/sb-price @@ -1,19 +1,24 @@ #!/bin/sh # Usage: -# price <url> <Name of currency> <icon> +# price <url> <Name of currency> <icon> <Price to show in> # price bat "Basic Attention Token" 🦁 # When the name of the currency is multi-word, put it in quotes. [ -z "$3" ] && exit 1 + +# use $4 as currency, if not passed in use "usd" as default +currency="${4:-usd}" interval="@14d" # History contained in chart preceded by '@' (7d = 7 days) dir="${XDG_DATA_HOME:-$HOME/.local/share}/crypto-prices" -pricefile="$dir/$1" -chartfile="$dir/$1-chart" +pricefile="$dir/$1-$currency" +chartfile="$dir/$1-$currency-chart" -updateprice() { ping -q -c 1 example.org >/dev/null 2>&1 && - curl -s "rate.sx/1$1" > "$pricefile" && - curl -s "rate.sx/$1$interval" > "$chartfile" ;} +updateprice() { temp="$(mktemp)" + curl -s "$currency.rate.sx/1$1" > "$temp" && + mv -f "$temp" "$pricefile" && + curl -s "$currency.rate.sx/$1$interval" > "$temp" && + mv -f "$temp" "$chartfile" ;} [ -d "$dir" ] || mkdir -p "$dir" @@ -35,4 +40,11 @@ case $BLOCK_BUTTON in 6) "$TERMINAL" -e "$EDITOR" "$0" ;; esac -printf "$3$%0.2f" "$(cat "$pricefile")" +case "$currency" in + usd) symb="$" ;; + gbp) symb="£" ;; + eur) symb="€" ;; + btc) symb="₿" ;; +esac + +printf "$3$symb%0.2f$after" "$(cat "$pricefile")" |
