Change sb-price to allow custom currency (#963)
e.g: price <url> <Name of currency> <icon> <Price to show in> price btc Bitcoin "" gbp
This commit is contained in:
parent
46b7d3f0c1
commit
f36f2fe539
1 changed files with 7 additions and 4 deletions
|
@ -1,19 +1,22 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# Usage:
|
# Usage:
|
||||||
# price <url> <Name of currency> <icon>
|
# price <url> <Name of currency> <icon> <Price to show in>
|
||||||
# price bat "Basic Attention Token" 🦁
|
# price bat "Basic Attention Token" 🦁
|
||||||
# When the name of the currency is multi-word, put it in quotes.
|
# When the name of the currency is multi-word, put it in quotes.
|
||||||
|
|
||||||
[ -z "$3" ] && exit 1
|
[ -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)
|
interval="@14d" # History contained in chart preceded by '@' (7d = 7 days)
|
||||||
dir="${XDG_DATA_HOME:-$HOME/.local/share}/crypto-prices"
|
dir="${XDG_DATA_HOME:-$HOME/.local/share}/crypto-prices"
|
||||||
pricefile="$dir/$1"
|
pricefile="$dir/$1"
|
||||||
chartfile="$dir/$1-chart"
|
chartfile="$dir/$1-chart"
|
||||||
|
|
||||||
updateprice() { ping -q -c 1 example.org >/dev/null 2>&1 &&
|
updateprice() { ping -q -c 1 example.org >/dev/null 2>&1 &&
|
||||||
curl -s "rate.sx/1$1" > "$pricefile" &&
|
curl -s "$currency.rate.sx/1$1" > "$pricefile" &&
|
||||||
curl -s "rate.sx/$1$interval" > "$chartfile" ;}
|
curl -s "$currency.rate.sx/$1$interval" > "$chartfile" ;}
|
||||||
|
|
||||||
[ -d "$dir" ] || mkdir -p "$dir"
|
[ -d "$dir" ] || mkdir -p "$dir"
|
||||||
|
|
||||||
|
@ -35,4 +38,4 @@ case $BLOCK_BUTTON in
|
||||||
6) "$TERMINAL" -e "$EDITOR" "$0" ;;
|
6) "$TERMINAL" -e "$EDITOR" "$0" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
printf "$3$%0.2f" "$(cat "$pricefile")"
|
printf "$3%0.2f$currency" "$(cat "$pricefile")"
|
||||||
|
|
Loading…
Reference in a new issue