Added bluetooth module in polybar
This commit is contained in:
58
config/.config/polybar/bars/scripts/bluetooth.sh
Executable file
58
config/.config/polybar/bars/scripts/bluetooth.sh
Executable file
@@ -0,0 +1,58 @@
|
||||
#!/bin/sh
|
||||
|
||||
bluetooth_print() {
|
||||
if bluetoothctl show | grep -q "Powered: yes"; then
|
||||
printf ''
|
||||
|
||||
devices_paired=$(bluetoothctl paired-devices | grep Device | cut -d ' ' -f 2)
|
||||
counter=0
|
||||
|
||||
for device in $devices_paired; do
|
||||
device_info=$(bluetoothctl info "$device")
|
||||
|
||||
if echo "$device_info" | grep -q "Connected: yes"; then
|
||||
device_alias=$(echo "$device_info" | grep "Alias" | cut -d ' ' -f 2-)
|
||||
|
||||
if [ $counter -gt 0 ]; then
|
||||
printf ", %s" "$device_alias"
|
||||
else
|
||||
printf " %s" "$device_alias"
|
||||
fi
|
||||
|
||||
counter=$((counter + 1))
|
||||
fi
|
||||
done
|
||||
|
||||
printf '\n'
|
||||
else
|
||||
echo ""
|
||||
fi
|
||||
}
|
||||
|
||||
bluetooth_toggle() {
|
||||
if bluetoothctl show | grep -q "Powered: no"; then
|
||||
bluetoothctl power on >> /dev/null
|
||||
sleep 1
|
||||
|
||||
devices_paired=$(bluetoothctl paired-devices | grep Device | cut -d ' ' -f 2)
|
||||
echo "$devices_paired" | while read -r line; do
|
||||
bluetoothctl connect "$line" >> /dev/null
|
||||
done
|
||||
else
|
||||
devices_paired=$(bluetoothctl devices Paired | grep Device | cut -d ' ' -f 2)
|
||||
echo "$devices_paired" | while read -r line; do
|
||||
bluetoothctl disconnect "$line" >> /dev/null
|
||||
done
|
||||
|
||||
bluetoothctl power off >> /dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
--toggle)
|
||||
bluetooth_toggle
|
||||
;;
|
||||
*)
|
||||
bluetooth_print
|
||||
;;
|
||||
esac
|
||||
Reference in New Issue
Block a user