dot

vizie's NixOS desktop: Hyprland, CachyOS kernel and gaming tweaks

14 lines644 bytesBourne Again Shell (bash)executable
1#!/usr/bin/env bash
2# Bluetooth state as one line of JSON for the Eww control center.
3NONE='{"available":false,"on":false,"device":"","label":"Unavailable"}'
4
5command -v bluetoothctl >/dev/null 2>&1 || { echo "$NONE"; exit 0; }
6show=$(timeout 2 bluetoothctl show 2>/dev/null)
7grep -q 'Powered:' <<<"$show" || { echo "$NONE"; exit 0; }
8
9if grep -q 'Powered: yes' <<<"$show"; then
10 dev=$(timeout 2 bluetoothctl devices Connected 2>/dev/null | head -1 | cut -d' ' -f3- | tr -d '"\\')
11 printf '{"available":true,"on":true,"device":"%s","label":"%s"}\n' "$dev" "${dev:-On}"
12else
13 echo '{"available":true,"on":false,"device":"","label":"Off"}'
14fi