Skip to content

Commit 9a8af3a

Browse files
authored
system-bluetooth-bluetoothctl: add battery reporting
1 parent 0b73c4e commit 9a8af3a

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

polybar-scripts/system-bluetooth-bluetoothctl/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ A shell script which displays the status of bluetooth and the paired devices.
44

55
Use the toggle option to power on the controller and try to connect to all paired devices or to disconnect all connections and turn off the controller.
66

7+
Note that bluetooth battery level reporting is an experimental feature which needs to be enabled by uncommenting and setting the `Experimental` line in `/etc/bluetooth/main.conf` to `true` and then restarting the `bluetooth.service`.
8+
79
![system-bluetooth-bluetoothctl](screenshots/1.png)
810

911

polybar-scripts/system-bluetooth-bluetoothctl/system-bluetooth-bluetoothctl.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,22 @@ bluetooth_print() {
1313

1414
if echo "$device_info" | grep -q "Connected: yes"; then
1515
device_alias=$(echo "$device_info" | grep "Alias" | cut -d ' ' -f 2-)
16+
device_battery=$(echo "$device_info" | grep "Battery" | awk -F'[()]' '{print $2}')
1617
18+
if [ -n "$device_battery" ]; then
19+
if [ "$device_battery" -gt 90 ]; then
20+
battery_icon="#21"
21+
elif [ "$device_battery" -gt 60 ]; then
22+
battery_icon="#22"
23+
elif [ "$device_battery" -gt 35 ]; then
24+
battery_icon="#23"
25+
elif [ "$device_battery" -gt 10 ]; then
26+
battery_icon="#24"
27+
else
28+
battery_icon="#25"
29+
fi
30+
device_alias="${device_alias} $battery_icon $device_battery%"
31+
fi
1732
if [ $counter -gt 0 ]; then
1833
printf ", %s" "$device_alias"
1934
else

0 commit comments

Comments
 (0)