ark/users/modules/eww/scripts/bluetooth

36 lines
929 B
Plaintext
Raw Normal View History

2022-09-14 15:35:52 +03:00
#!/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"'" }'
2022-09-14 17:58:08 +03:00
sleep 10
2022-09-14 15:35:52 +03:00
done