From 96d6f631d121f0ad4e88c4841e4712185f741892 Mon Sep 17 00:00:00 2001 From: Alexander Bocken Date: Sat, 4 Jul 2020 21:36:11 +0200 Subject: [PATCH] only show disconnect option if devices are connected --- bt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/bt b/bt index 5874275..0b8ac8b 100755 --- a/bt +++ b/bt @@ -6,8 +6,7 @@ AUTOTRUST=false BLACKLIST=${XDG_DATA_HOME:-$HOME/.local/share}/bt/blacklist PAIRLIST=${XDG_DATA_HOME:-$HOME/.local/share}/bt/paired -actions="disconnect -pair +actions="pair unpair" [ "$AUTOTRUST" = false ] && actions="${actions} @@ -52,12 +51,20 @@ update_pair_list(){ fi } + #start scanning as early as possible to speed up pairing process #=> maybe use an option to do this? Otherwise ever invocation of bt powers on the controller. power on scan on update_pair_list & +# shellcheck disable=SC1091 +if bluetoothctl devices | awk '{print "bluetoothctl info "$2}' | . /dev/stdin | grep -q "Connected: yes" +then + actions="$(printf "disconnect\n%s" "$actions")" +fi + + #Compile list of all Bluetooth IDS of paired devices (from bluetoothctl and from hardcoded list) bt_IDS="$( ( bluetoothctl paired-devices && cat "$PAIRLIST" ) | sort -u | awk '{print $2}' )"