Browse Source

++currency

master
Maxim Likhachev 5 years ago
parent
commit
46720e05e3
  1. 4
      README.md
  2. 38
      currency

4
README.md

@ -113,3 +113,7 @@ will create the symbolic link for each script in the \<path> directory. @@ -113,3 +113,7 @@ will create the symbolic link for each script in the \<path> directory.
- [x-open](x-open) opens files via xdg-open (on Linux systems) or via open command (on MacOS).
- [xstab](xstab) runs [st](https://st.suckless.org/) terminal with the [tabbed](https://tools.suckless.org/tabbed/).
## Other
- [currency](currency) shows the currency rate.

38
currency

@ -0,0 +1,38 @@ @@ -0,0 +1,38 @@
#!/bin/bash
#
# Simple currency converter
#
SHORT_OUTPUT=false
exchange() {
local api_url="https://api.exchangeratesapi.io/latest?base=${1^^}&symbols=${2^^}"
curl -s -q -L "$api_url" \
| jq -r --arg short "$SHORT_OUTPUT" '
def round:
.*100.0 + 0.5 | floor / 100.0;
if ($short == "true") then
.rates | to_entries | .[] | (.value | round | tostring)
else
"1 " + .base + " ≈ "
+ (.rates | to_entries | .[] | (.value | round | tostring) + " " + .key)
end
'
}
if [ $# -le 1 ]; then
echo "USAGE: $(basename "$0") ?-s? FROM TO1,TO2,...,TOn"
echo " e.g: $(basename "$0") ?-s? USD EUR,RUB"
echo "Set -s to show only value."
else
if [ "$1" == "-s" ]; then
SHORT_OUTPUT=true
shift
fi
exchange "$@"
fi
Loading…
Cancel
Save