Files
dotfiles/.config/waybar/scripts/bt_toggle.sh

19 lines
580 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
status() { bluetoothctl show 2>/dev/null | awk '/Powered:/ {print tolower($2); exit}'; } # yes/no
print() {
s="$(status)"; s="${s:-no}"
if [ "$s" = "yes" ]; then
echo '{"text":"","class":"on","tooltip":"Bluetooth: on (click to toggle)"}'
else
echo '{"text":"","class":"off","tooltip":"Bluetooth: off (click to toggle)"}'
fi
}
case "${1:---print}" in
--toggle) [ "$(status)" = "yes" ] && bluetoothctl power off || bluetoothctl power on ;;
--print) : ;;
*) echo "Usage: $0 [--toggle|--print]"; exit 1 ;;
esac
print