diff --git a/.config/polybar/config b/.config/polybar/config index 1bb5c87..a4cb908 100644 --- a/.config/polybar/config +++ b/.config/polybar/config @@ -53,7 +53,7 @@ font-4 = "Font Awesome 5 Brands:pixelsize=16;3" modules-left = bspwm modules-center = title -modules-right = pulseaudio backlight-acpi wlan eth battery battery-low date powermenu +modules-right = btc pulseaudio backlight-acpi wlan eth battery battery-low date powermenu tray-maxsize = 30 tray-position = right diff --git a/.config/polybar/modules b/.config/polybar/modules index 0423016..b68031c 100644 --- a/.config/polybar/modules +++ b/.config/polybar/modules @@ -28,6 +28,15 @@ type = internal/xwindow label = %title:0:50:...% label-foreground = ${colors.white-bright} +[module/btc] +type = custom/script +interval = 300 + +exec = $HOME/.scripts/panel/btc.sh + +label =  %output% +label-foreground = ${colors.white-bright} + ; https://github.com/polybar/polybar/wiki/Module:-pulseaudio [module/pulseaudio] type = internal/pulseaudio diff --git a/.config/zsh/.zshrc b/.config/zsh/.zshrc index ed0782d..479eee9 100644 --- a/.config/zsh/.zshrc +++ b/.config/zsh/.zshrc @@ -156,6 +156,7 @@ alias vp="$HOME/.scripts/vimplugin.sh" alias mpvshuffle="$HOME/.scripts/mpv.sh shuffle" # Other +alias crypto="curl 'https://rate.sx/?qF'" alias IP="curl https://ifconfig.me" alias len="xclip -o | wc -m" alias length="rofi -dmenu -i -p 'String length' -lines 0 | tr -d '\n' | wc -m" diff --git a/.scripts/panel/btc.sh b/.scripts/panel/btc.sh new file mode 100755 index 0000000..c1367c9 --- /dev/null +++ b/.scripts/panel/btc.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +# Enable mathematics in POSIX shell +calc() { awk "BEGIN { printf(\"%.2f\", $*) }"; } + +output() { + [ -z "$1" ] || [ -z "$2" ] && return 1 + + url="$1" + price="$2" + + price_old="$(curl -s $url | jq -cr '.data.amount')" + difference=$(calc "$price / $price_old * 100 - 100") + + # Get symbol and color + old_higher=$(calc "$price < $price_old" | cut -c 1) + if [ $old_higher -eq 0 ]; then + symbol="" + color="$COLOR2" + else + symbol="" + color="$COLOR1" + fi + + # Result + echo "%{F$color}$symbol $difference%%{F$COLOR15}" +} + +# Get dates +date_yesterday="$(date -d 'yesterday' +'%Y-%m-%d')" +date_last_week="$(date -d 'last week' +'%Y-%m-%d')" + +# Get API URLs +url="https://api.coinbase.com/v2/prices/BTC-USD/spot" +url_yesterday="${url}?date=$date_yesterday" +url_last_week="${url}?date=$date_last_week" + +# Current price +price="$(curl -s $url | jq -cr '.data.amount')" + +# Create output formatting +difference_yesterday_output="d $(output $url_yesterday $price)" +difference_last_week_output="w $(output $url_last_week $price)" + +echo "\$$price $difference_yesterday_output $difference_last_week_output"