Files
config-backup/i3/bluetooth_status.sh
ION606 1fc598c6a0 merge
2026-01-03 12:55:26 -08:00

40 lines
922 B
Bash

#!/usr/bin/env bash
# check status of a specific bluetooth device via bluetoothctl
# check if bluetooth service is active
if ! systemctl is-active --quiet bluetooth.service; then
echo "Bluetooth off" # icon or text when BT is down
exit 0
fi
# check if controller is powered on
if ! bluetoothctl show | grep -q "Powered: yes"; then
echo "BT ctrl off"
exit 0
fi
# check connected status
mapfile -t macs < <(bluetoothctl devices | awk '{print $2}')
connected_name=""
for mac in "${macs[@]}"; do
# get info for this device
info=$(bluetoothctl info "$mac")
if echo "$info" | grep -q "Connected: yes"; then
# extract Name:
name=$(echo "$info" | grep "^\\s*Name:" | sed 's/.*Name: //')
connected_name="$name"
break
fi
done
if [[ -n "$connected_name" ]]; then
# you can replace the icon with a nerd-font icon if you use one
echo "$connected_name"
else
echo " Disconnected"
fi