chg: Tidy up bluetooth-toggle

This commit is contained in:
Sayantan Santra 2024-09-22 21:42:25 -05:00
parent 915bb4fce6
commit 9301a586df
Signed by: SinTan1729
GPG key ID: 0538DD402EA50898

View file

@ -4,19 +4,21 @@
# I use it with a shortcut. # I use it with a shortcut.
# #
BLUETOOTH_DEVICE=$(bluetoothctl list | grep dongle | awk '{print $2}') DONGLE_MAC=$(bluetoothctl list | grep dongle | awk '{print $2}')
if [ -z $BLUETOOTH_DEVICE ]; then INTERNAL_MAC=$(bluetoothctl list | grep internal | awk '{print $2}')
BLUETOOTH_DEVICE=$(bluetoothctl list | head -1 | awk '{print $2}')
if [ -z $DONGLE_MAC ]; then
DEVICE_MAC=$INTERNAL_MAC
else else
BLUETOOTH_DEVICE_OTHER=$(bluetoothctl list | grep internal | awk '{print $2}') DEVICE_MAC=$DONGLE_MAC
echo -e "select $BLUETOOTH_DEVICE_OTHER\npower off" | bluetoothctl echo -e "select $INTERNAL_MAC\npower off" | bluetoothctl
fi fi
if [ $(bluetoothctl show $BLUETOOTH_DEVICE | grep Powered | grep -c yes) == 1 ]; then if [ $(bluetoothctl show $DEVICE_MAC | grep Powered | grep -c yes) == 1 ]; then
echo -e "select $BLUETOOTH_DEVICE\npower off" | bluetoothctl echo -e "select $DEVICE_MAC\npower off" | bluetoothctl
else else
if [ $(rfkill --output-all | grep bluetooth | grep -c blocked) != 0 ]; then if [ $(rfkill --output-all | grep bluetooth | grep -c blocked) != 0 ]; then
rfkill unblock bluetooth rfkill unblock bluetooth
fi fi
echo -e "select $BLUETOOTH_DEVICE\npower on" | bluetoothctl echo -e "select $DEVICE_MAC\npower on" | bluetoothctl
fi fi