allow for '🔗' in device name and other small improvements

This commit is contained in:
Alexander Bocken 2021-08-23 16:10:25 +02:00
parent 11b95a1e05
commit 0ade87fa16
Signed by: Alexander
GPG Key ID: 1D237BE83F9B05E8

11
bt
View File

@ -1,5 +1,6 @@
#!/bin/sh #!/bin/sh
#load config #load config
#shellcheck disable=SC1091
. "${XDG_CONFIG_HOME:-$HOME/.config}/bt/config" . "${XDG_CONFIG_HOME:-$HOME/.config}/bt/config"
"$AUTOTRUST" || actions="$(printf '%s\ntrust\n' "$actions")" "$AUTOTRUST" || actions="$(printf '%s\ntrust\n' "$actions")"
@ -65,6 +66,7 @@ fi
startup & startup &
update_pair_list & update_pair_list &
# shellcheck disable=SC1091
connected_ids="$(bluetoothctl devices | awk '{print "bluetoothctl info "$2}' | . /dev/stdin | grep -E '(^Device |Connected:)' | sed -e 'N;s/\n/;/' | grep 'Connected: yes' | cut -d' ' -f2,5)" connected_ids="$(bluetoothctl devices | awk '{print "bluetoothctl info "$2}' | . /dev/stdin | grep -E '(^Device |Connected:)' | sed -e 'N;s/\n/;/' | grep 'Connected: yes' | cut -d' ' -f2,5)"
[ -z "$connected_ids" ] || [ -z "$connected_ids" ] ||
@ -93,7 +95,8 @@ paired_devices="$(echo "$paired_devices_with_id" | while read -r device_line; do
fi fi
done)" done)"
echo "paired_devices:$paired_devices" echo "paired_devices:"
echo "$paired_devices"
disp_devices="$( echo "$paired_devices" | grep -vf "$BLACKLIST" )" disp_devices="$( echo "$paired_devices" | grep -vf "$BLACKLIST" )"
@ -118,7 +121,7 @@ if [ "$disp_devices" = "" ];then
dmenu -i -p 'What BT action would you like to perform:') dmenu -i -p 'What BT action would you like to perform:')
else else
choice=$( ( echo "$disp_devices_with_links" && printf "%s\n%s" "$actions" "$poweroption" ) | choice=$( ( echo "$disp_devices_with_links" && printf "%s\n%s" "$actions" "$poweroption" ) |
dmenu -i -p 'What BT action would you like to perform:' | tr -d '🔗') dmenu -i -p 'What BT action would you like to perform:' | sed 's/🔗$//')
fi fi
cleanup(){ cleanup(){
@ -205,9 +208,9 @@ case $choice in
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}' )" 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 ] if [ "$( echo "$untrusted_devices" | wc -l )" -gt 0 ]
then then
choice=$( echo "$untrusted_devices" | dmenu -l 10 -i -p 'remove which paired device?') choice=$( echo "$untrusted_devices" | dmenu -l 10 -i -p 'trust which paired device?')
else else
notify-send "bt" "No paired devices that are not trusted" notify-send "bt" "No paired devices that are not trusted already."
fi fi
if [ -n "$choice" ]; then if [ -n "$choice" ]; then
dev_no=$( echo "$paired_devices" | nl | grep -P "[0-9]+\t$choice$" | awk '{print $1}') dev_no=$( echo "$paired_devices" | nl | grep -P "[0-9]+\t$choice$" | awk '{print $1}')