dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

dwmblock-bluetooth (1064B)


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