Commit 5bb2c3c339b3
Changed files (2)
dots
config
raffi
scripts
dots/config/raffi/scripts/bluetooth-raffi
@@ -0,0 +1,37 @@
+#!/usr/bin/env bash
+# List paired Bluetooth devices for raffi script filter.
+# Outputs Alfred Script Filter JSON format.
+# Usage: bluetooth-raffi [query]
+set -euo pipefail
+
+query="${1:-}"
+
+items="[]"
+while IFS= read -r line; do
+ mac=$(echo "$line" | awk '{print $2}')
+ [[ -z "$mac" ]] && continue
+
+ info=$(bluetoothctl info "$mac" 2>/dev/null) || continue
+ name=$(echo "$info" | grep "Alias:" | sed 's/.*Alias: //')
+ connected=$(echo "$info" | grep -P '^\tConnected:' | sed 's/.*Connected: //')
+ icon=$(echo "$info" | grep "Icon:" | sed 's/.*Icon: //')
+
+ [[ -z "$name" ]] && name="$mac"
+ [[ -z "$icon" ]] && icon="bluetooth"
+
+ if [[ "$connected" == "yes" ]]; then
+ status="🟢 Connected"
+ else
+ status="⚪ Disconnected"
+ fi
+
+ filter="${name} ${mac} ${status}"
+ if [[ -n "$query" ]] && ! echo "$filter" | grep -qi "$query"; then
+ continue
+ fi
+
+ items=$(jq --arg name "$name" --arg mac "$mac" --arg status "$status" \
+ '. + [{"title": $name, "subtitle": "\($status) — \($mac)", "arg": $mac}]' <<< "$items")
+done < <(bluetoothctl devices 2>/dev/null)
+
+jq -n --argjson items "$items" '{"items": $items}'
dots/config/raffi/raffi.yaml
@@ -86,6 +86,12 @@ addons:
command: ~/.config/raffi/scripts/niri-windows-raffi
icon: window-close
action: niri msg action close-window --id {value}
+ - name: Bluetooth
+ keyword: bt
+ command: ~/.config/raffi/scripts/bluetooth-raffi
+ icon: bluetooth
+ action: bluetoothctl connect {value}
+ secondary_action: bluetoothctl disconnect {value}
- name: IDs & Timestamps
keyword: uid
command: ~/.config/raffi/scripts/uid-raffi