From 234e781b6b59ab0b9d29173932b893ce23805d88 Mon Sep 17 00:00:00 2001 From: Alexander Bocken Date: Mon, 6 Jul 2020 12:39:22 +0200 Subject: [PATCH] only list untrusted devices in trust menu --- README.md | 2 +- bt | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b96b673..389c4e0 100644 --- a/README.md +++ b/README.md @@ -53,4 +53,4 @@ If you have troubles with an uninstall, _additionally_ run `which bt | xargs rm` - only show disconnect option if devices are already connected -> **Implemented** - 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 +- only list not trusted devices in trust menu -> **Implemented** diff --git a/bt b/bt index 1276aad..7d4512d 100755 --- a/bt +++ b/bt @@ -166,7 +166,17 @@ case $choice in touch "$PAIRLIST" fi fi;; - "trust") choice=$( echo "$paired_devices" | dmenu -l 10 -i -p 'remove which paired device?') + + "trust") + #search through all devices which are connected and only list those as options + # shellcheck disable=SC1091 + untrusted_devices="$( awk '{print "bluetoothctl info "$2}' "$PAIRLIST" | . /dev/stdin | grep -E '(Alias:|Trusted:)' | sed -e 'N;s/\n/;/;s/^.?*Alias: //' | grep "Trusted: no" | awk -F ';' '{print $1}' )" + if [ "$( echo "$untrusted_devices" | wc -l )" -gt 0 ] + then + choice=$( echo "$untrusted_devices" | dmenu -l 10 -i -p 'remove which paired device?') + else + notify-send "Bluetooth" "No paired devices that are not trusted" + fi if [ -n "$choice" ]; then dev_no=$( echo "$paired_devices" | nl | grep -P "[0-9]+\t$choice$" | awk '{print $1}') dev_id=$( echo "$bt_IDS" | nl | grep -P "^.*$dev_no\t" | awk '{print $2}' )