only show disconnect option if devices are connected

This commit is contained in:
Alexander Bocken 2020-07-04 21:36:11 +02:00
parent 04182df41c
commit 96d6f631d1

11
bt
View File

@ -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}' )"