dwmblock-bluetooth (1145B)
1 #!/bin/sh 2 # dwmblocks script for bluetooth 3 4 case "$BUTTON" in 5 1) 6 if pgrep -f bluetoothctl >/dev/null 2>&1; then 7 wmctrl -Fa bluetoothctl 8 else 9 "$TERMINAL" -e bluetoothctl 10 fi 11 pkill -RTMIN+8 dwmblocks 12 ;; 13 3) 14 notify Bluetooth "Toggling bluetooth..." 15 rfkill toggle bluetooth 16 pkill -RTMIN+8 dwmblocks 17 ;; 18 6) "$TERMINAL" -e "$EDITOR" "$0" 19 ;; 20 esac 21 22 bt="$(bluetoothctl show)" 23 res="" 24 if [ "$bt" = "No default controller available" ]; then 25 res=" 🛑" 26 elif printf '%s' "$bt" | grep '^\s*Powered: no' >/dev/null 2>&1; then 27 res=' ❌' 28 elif printf '%s' "$bt" | grep '^\s*Powered: yes' >/dev/null 2>&1; then 29 res='' 30 while read -r uuid; do 31 info="$(bluetoothctl info "$uuid")" 32 if printf '%s' "$info" | grep '^\s*Connected: yes' >/dev/null 2>&1; then 33 res="$res $(printf '%s' "$info" | awk -F': ' ' 34 /Icon: audio-headset/ { printf "🎧 " } 35 /Icon: audio-card/ { printf "📢" } 36 /Battery Percentage/ { split($2, a, "[ ()]*"); printf a[2]"%" } 37 ')" 38 fi 39 done <<EOF 40 $(bluetoothctl devices | cut -f2 -d' ') 41 EOF 42 fi 43 printf '%s' "$res"