From cbd1b2f83d128c362c46b03c3c24681d2ce5912c Mon Sep 17 00:00:00 2001 From: Alexander Bocken Date: Thu, 23 Jul 2020 20:47:11 +0200 Subject: [PATCH] selecting connected device disconnects it --- README.md | 1 + bt | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 050e546..f2054fb 100644 --- a/README.md +++ b/README.md @@ -62,3 +62,4 @@ This should only be an issue if `bluetoothctl scan off` is unreliable for you th - find a way to get something similar to `grep -vf` without the need of temp files. - only list connected devices to disconnect from, not all paired devices -> **Implemented** - only list not trusted devices in trust menu -> **Implemented** +- selecting already connected device disconnects it -> **Implemented** diff --git a/bt b/bt index a5ad94c..bd7343f 100755 --- a/bt +++ b/bt @@ -221,8 +221,13 @@ case $choice in [ "$dev_no" != "" ] && dev_id=$( echo "$bt_IDS" | nl | grep -P "^.*$dev_no\t" | awk '{print $2}') if [ -n "$dev_id" ]; then power on - bluetoothctl devices | grep -q "$dev_id" || bluetoothctl pair "$dev_id" - bluetoothctl connect "$dev_id" + if bluetoothctl info "$dev_id" | grep -q "Connected: yes" + then + bluetoothctl disconnect "$dev_id" + else + bluetoothctl devices | grep -q "$dev_id" || bluetoothctl pair "$dev_id" + bluetoothctl connect "$dev_id" + fi fi;; esac