only attempt to pair on connect if necessary

This commit is contained in:
Alexander Bocken 2020-07-07 12:24:46 +02:00
parent 47f83247e4
commit 774c5f7d1c

3
bt
View File

@ -186,6 +186,7 @@ case $choice in
#search through all devices which are connected and only list those as options #search through all devices which are connected and only list those as options
# shellcheck disable=SC1091 # shellcheck disable=SC1091
connected_devices="$( bluetoothctl devices | awk '{print "bluetoothctl info "$2}' | . /dev/stdin | grep -E '(Alias:|Connected:)' | sed -e 'N;s/\n/;/;s/^.?*Alias: //' | grep "Connected: yes" | awk -F ';' '{print $1}' )" connected_devices="$( bluetoothctl devices | awk '{print "bluetoothctl info "$2}' | . /dev/stdin | grep -E '(Alias:|Connected:)' | sed -e 'N;s/\n/;/;s/^.?*Alias: //' | grep "Connected: yes" | awk -F ';' '{print $1}' )"
echo "$connected_devices"
#only open dmenu prompt if there is more than one connected device #only open dmenu prompt if there is more than one connected device
if [ "$( echo "$connected_devices" | wc -l )" -gt 1 ] if [ "$( echo "$connected_devices" | wc -l )" -gt 1 ]
then then
@ -209,7 +210,7 @@ case $choice in
[ "$dev_no" != "" ] && dev_id=$( echo "$bt_IDS" | nl | grep -P "^.*$dev_no\t" | awk '{print $2}') [ "$dev_no" != "" ] && dev_id=$( echo "$bt_IDS" | nl | grep -P "^.*$dev_no\t" | awk '{print $2}')
if [ -n "$dev_id" ]; then if [ -n "$dev_id" ]; then
power on power on
bluetoothctl pair "$dev_id" bluetoothctl devices | grep -q "$dev_id" || bluetoothctl pair "$dev_id"
bluetoothctl connect "$dev_id" bluetoothctl connect "$dev_id"
fi;; fi;;
esac esac