From 95ac330d0b8b837b5c188d01d34ed5b01c7ec81f Mon Sep 17 00:00:00 2001 From: Stacy Harper Date: Thu, 25 Mar 2021 20:38:13 +0100 Subject: [PATCH] Add a simple bluetooth menu Signed-off-by: Stacy Harper Signed-off-by: Maarten van Gompel --- scripts/core/sxmo_appmenu.sh | 1 + scripts/core/sxmo_bluetoothmenu.sh | 25 +++++++++++++++++++++++++ scripts/core/sxmo_common.sh | 2 ++ 3 files changed, 28 insertions(+) create mode 100755 scripts/core/sxmo_bluetoothmenu.sh diff --git a/scripts/core/sxmo_appmenu.sh b/scripts/core/sxmo_appmenu.sh index 2240517..5028366 100755 --- a/scripts/core/sxmo_appmenu.sh +++ b/scripts/core/sxmo_appmenu.sh @@ -401,6 +401,7 @@ programchoicesinit() { $icon_phn Dialer ^ 0 ^ sxmo_modemdial.sh $icon_msg Texts ^ 0 ^ sxmo_modemtext.sh $icon_usr Contacts ^ 0 ^ sxmo_contactmenu.sh + $(command -v bluetoothctl >/dev/null && echo "$icon_bth Bluetooth ^ 0 ^ sxmo_bluetoothmenu.sh") $(command -v megapixels >/dev/null && echo "$icon_cam Camera ^ 0 ^ GDK_SCALE=2 megapixels") $icon_net Networks ^ 0 ^ sxmo_networks.sh $icon_mus Audio ^ 0 ^ sxmo_appmenu.sh audioout diff --git a/scripts/core/sxmo_bluetoothmenu.sh b/scripts/core/sxmo_bluetoothmenu.sh new file mode 100755 index 0000000..5591684 --- /dev/null +++ b/scripts/core/sxmo_bluetoothmenu.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env sh + +devicemenu() { + while true; do + DEVICES="$(bluetoothctl devices | awk '{ $1=""; printf $2; $2=""; printf " ^" $0 "\n" }')" + ENTRIES="$(echo "$DEVICES" | sed 's|.* ^ ||' | xargs -0 printf "Close Menu\nDisconnect\n%s")" + + PICKED="$( + echo "$ENTRIES" | + sxmo_dmenu_with_kb.sh -i -c -l 10 -p "Devices" + )" + + if echo "$PICKED" | grep -q "Close Menu"; then + exit + elif echo "$PICKED" | grep -q "Disconnect"; then + st -e sh -c "bluetoothctl disconnect; sleep 1" + continue + else + devicemac="$(echo "$DEVICES" | grep " \^ $PICKED$" | sed 's| ^ .*||' )" + st -e sh -c "bluetoothctl connect $devicemac; sleep 1" + fi + done +} + +devicemenu diff --git a/scripts/core/sxmo_common.sh b/scripts/core/sxmo_common.sh index 1b2e06f..becf585 100644 --- a/scripts/core/sxmo_common.sh +++ b/scripts/core/sxmo_common.sh @@ -226,6 +226,8 @@ icon_chk="" icon_and="" # shellcheck disable=SC2034 icon_wif="" +# shellcheck disable=SC2034 +icon_bth="" #allow the user to override icons if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/icons" ]; then