2023-08-07 20:37:41 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2023-08-09 22:11:09 -04:00
|
|
|
FILE="$HOME/.config/.bluetooth"
|
|
|
|
|
2023-08-07 20:37:41 -04:00
|
|
|
get_device() {
|
|
|
|
if [[ $(bluetoothctl devices Connected) != "" ]]; then
|
|
|
|
bluetoothctl devices Connected | awk '{ for (i = 3; i <= NF; i++) { printf("%s ", $i) } printf("\n") }'
|
|
|
|
else
|
|
|
|
echo "Disconnected"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
get_state() {
|
|
|
|
if [[ "$(rfkill list | grep -A 1 hci0 | grep -o no)" == "no" ]]; then
|
2023-08-20 00:01:31 -04:00
|
|
|
eww update bluetooth_icon=" "
|
2023-08-09 22:11:09 -04:00
|
|
|
echo " " > "$FILE"
|
2023-08-07 20:37:41 -04:00
|
|
|
else
|
2023-08-20 00:01:31 -04:00
|
|
|
eww update bluetooth_icon=" "
|
2023-08-09 22:11:09 -04:00
|
|
|
echo " " > "$FILE"
|
2023-08-07 20:37:41 -04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
[[ "$1" == "device" ]] && get_device
|
2023-08-20 00:01:31 -04:00
|
|
|
if [[ "$1" == "toggle" ]]; then
|
|
|
|
rfkill toggle bluetooth
|
|
|
|
get_state
|
|
|
|
fi
|
2023-08-07 20:37:41 -04:00
|
|
|
|
|
|
|
if [[ $1 == "icon" ]]; then
|
|
|
|
while true; do
|
|
|
|
get_state
|
2023-08-09 22:11:09 -04:00
|
|
|
tail "$FILE"
|
2023-08-20 11:44:31 -04:00
|
|
|
sleep 1
|
2023-08-07 20:37:41 -04:00
|
|
|
done
|
|
|
|
fi
|