ark/users/modules/eww/scripts/bluetooth
2022-09-14 17:58:08 +03:00

36 lines
929 B
Bash
Executable File

#!/usr/bin/env bash
declare -A baticon=([10]="󰁺" [20]="󰁻" [30]="󰁼" [40]="󰁽" [50]="󰁾" [60]="󰁿" [70]="󰂀" [80]="󰂁" [90]="󰂂" [100]="󰁹")
while true; do
powered=$(bluetoothctl show | rg Powered | cut -f 2- -d ' ')
status=$(bluetoothctl info)
battery=$(echo "$status" | tail -1 | awk '{print $4 }' | tr -d '()')
name=$(echo "$status" | rg Name | cut -f 2- -d ' ')
if [ "$powered" = "yes" ]; then
if [ "$status" != "Missing device address argument" ]; then
if [ "$battery" -le 100 ] && [ "$battery" -ge 0 ]; then
text="$name ${baticon[$battery]}"
else
text="$name"
fi
icon=""
color="#b4befe"
else
icon=""
text="Disconnected"
color="#45475a"
fi
else
icon=""
text="Bluetooth off"
color="#45475a"
fi
echo '{ "icon": "'"$icon"'", "text": "'"$text"'", "color": "'"$color"'" }'
sleep 10
done