1 #!/bin/sh 2 3 # Usage: 4 # price <url> <Name of currency> <icon> 5 # price bat "Basic Attention Token" 🦁 6 # When the name of the currency is multi-word, put it in quotes. 7 8 [ -z "$3" ] && exit 1 9 interval="@14d" # History contained in chart preceded by '@' (7d = 7 days) 10 dir="${XDG_DATA_HOME:-$HOME/.local/share}/crypto-prices" 11 pricefile="$dir/$1" 12 chartfile="$dir/$1-chart" 13 14 updateprice() { ping -q -c 1 example.org >/dev/null 2>&1 && 15 curl -s "rate.sx/1$1" > "$pricefile" && 16 curl -s "rate.sx/$1$interval" > "$chartfile" ;} 17 18 [ -d "$dir" ] || mkdir -p "$dir" 19 20 [ "$(stat -c %x "$pricefile" 2>/dev/null | cut -d' ' -f1)" != "$(date '+%Y-%m-%d')" ] && 21 updateprice "$1" 22 23 case $BLOCK_BUTTON in 24 1) setsid "$TERMINAL" -e less -Srf "$chartfile" ;; 25 2) notify-send -u low "$3 Updating..." "Updating $2 price..." 26 updateprice "$1" && notify-send "$3 Update complete." "$2 price is now 27 \$$(cat "$pricefile")" ;; 28 3) uptime="$(date -d "$(stat -c %x "$pricefile")" '+%D at %T' | sed "s|$(date '+%D')|Today|")" 29 notify-send "$3 $2 module" "\- <b>Exact price: \$$(cat "$pricefile")</b> 30 - Left click for chart of changes. 31 - Middle click to update. 32 - Shows 🔃 if updating prices. 33 - <b>Last updated: 34 $uptime</b>" ;; 35 6) "$TERMINAL" -e "$EDITOR" "$0" ;; 36 esac 37 38 printf "$3$%0.2f" "$(cat "$pricefile")"