From fbbea1e4a92bbd96c4db33c50a9c441a5f844af1 Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Sat, 8 Jul 2023 05:37:51 +0900 Subject: bin: update menus MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Robert Günzler --- bin/bluemenu | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 bin/bluemenu (limited to 'bin/bluemenu') diff --git a/bin/bluemenu b/bin/bluemenu new file mode 100755 index 0000000..22ac87b --- /dev/null +++ b/bin/bluemenu @@ -0,0 +1,59 @@ +#!/bin/bash + +set -e +[ -n "$DEBUG" ] && set -x +export UNSAFE=1 + +# notifysend() { +# [ -z "$notifyicon" ] && notifyicon=bluetooth +# local msg=$1 +# shift 1 +# echo "$msg" +# notification_id=$(notify-send "bluetooth" "$msg" -i "$(iconez -sn "$notifyicon")" --print-id "$@") +# } + +if [ -n "$BTON" ]; then + bluetoothctl power on + exit $? +fi + +if [ -n "$BTOFF" ]; then + bluetoothctl power off + exit $? +fi + +if [ -n "$BTCONNECT" ]; then + if [ -n "$REEXEC" ]; then + addr=$1 + + if bluetoothctl devices Connected | grep -q "$addr"; then + bluetoothctl disconnect "$addr" + else + bluetoothctl connect "$addr" + sleep 2 + # hack to make wireplumber detect bt audio device + pkill -USR2 wireplumber + fi + + exit $? + fi + + bluetoothctl power on + bluetoothctl devices | + while read -r btdev; do + name=$(cut -d' ' -f3 <<<"$btdev") + addr=$(cut -d' ' -f2 <<<"$btdev") + + jq -cnr \ + --arg label "$name $addr" \ + --arg addr "$addr" \ + '{l:$label,x:(["env BTCONNECT=1 REEXEC=1 bluemenu", $addr]|join(" "))}' + done | + jq -cs '{p:"bluemenu", o:.}' | + mkmenu + + exit $? +fi + +jq -cn '{p:"bluetooth",o:[{l:"power on",x:"env BTON=1 bluemenu"},{l:"power off",x:"env BTOFF=1 bluemenu"},{l:"connect...",x:"env BTCONNECT=1 bluemenu"}]}' | + mkmenu -- cgit 1.4.1