move de_alias to func
This commit is contained in:
parent
74551c09a5
commit
eefd1753a5
45
bt
45
bt
@ -71,31 +71,28 @@ update_pair_list &
|
|||||||
# shellcheck disable=SC1091
|
# 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" ] ||
|
de_alias(){
|
||||||
connected_devices="$(echo "$connected_ids" | while read -r id; do
|
while read -r id; do
|
||||||
if grep -q "$id" "$ALIASLIST"; then
|
if grep -q "$id" "$ALIASLIST"; then
|
||||||
grep "$id" "$ALIASLIST" | cut -d' ' --complement -f1
|
grep "$id" "$ALIASLIST" | cut -d' ' --complement -f1
|
||||||
else
|
else
|
||||||
grep "$id" "$PAIRLIST" | cut -d' ' --complement -f1,2
|
grep "$id" "$PAIRLIST" | cut -d' ' --complement -f1,2
|
||||||
fi
|
fi
|
||||||
done)"
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[ -z "$connected_ids" ] ||
|
||||||
|
connected_devices="$( echo "$connected_ids" | de_alias )"
|
||||||
|
|
||||||
|
# shellcheck disable=SC2154
|
||||||
"$include_disconnect_option" &&
|
"$include_disconnect_option" &&
|
||||||
[ -n "$connected_devices" ] &&
|
[ -n "$connected_devices" ] &&
|
||||||
actions="$(printf "disconnect\n%s" "$actions")"
|
actions="$(printf "disconnect\n%s" "$actions")"
|
||||||
|
|
||||||
#Compile list of all device Names of paired devices (from bluetoothctl and from hardcoded list)
|
#Compile list of all device ids of paired devices (from bluetoothctl and from hardcoded list)
|
||||||
paired_devices_with_id="$( ( bluetoothctl paired-devices && cat "$PAIRLIST" ) | sort -u | cut -d' ' --complement -f1)"
|
connected_ids="$( ( bluetoothctl paired-devices && cat "$PAIRLIST" ) | sort -u | cut -d' ' -f2)"
|
||||||
bt_IDS="$(echo "$paired_devices_with_id" | cut -d' ' -f1)"
|
paired_devices="$( echo "$connected_ids" | de_alias )"
|
||||||
#de-alias
|
|
||||||
paired_devices="$(echo "$paired_devices_with_id" | while read -r device_line; do
|
|
||||||
id="$(echo "$device_line" | cut -d' ' -f1)"
|
|
||||||
if grep -q "$id" "$ALIASLIST"; then
|
|
||||||
grep "$id" "$ALIASLIST" | cut -d' ' --complement -f1
|
|
||||||
else
|
|
||||||
echo "$device_line" | cut -d' ' --complement -f1
|
|
||||||
fi
|
|
||||||
done)"
|
|
||||||
|
|
||||||
echo "paired_devices:"
|
echo "paired_devices:"
|
||||||
echo "$paired_devices"
|
echo "$paired_devices"
|
||||||
@ -208,13 +205,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
|
||||||
untrusted_device_ids="$( awk '{print "bluetoothctl info "$2}' "$PAIRLIST" | . /dev/stdin | grep -E '(Device |Trusted:)' | sed -e 'N;s/\n/;/;s/^.?*Alias: //' | grep "Trusted: no" | cut -d' ' -f2 )"
|
untrusted_device_ids="$( awk '{print "bluetoothctl info "$2}' "$PAIRLIST" | . /dev/stdin | grep -E '(Device |Trusted:)' | sed -e 'N;s/\n/;/;s/^.?*Alias: //' | grep "Trusted: no" | cut -d' ' -f2 )"
|
||||||
untrusted_devices="$( echo "$untrusted_device_ids" | while read -r id; do
|
untrusted_devices="$( echo "$untrusted_device_ids" | de_alias )"
|
||||||
if grep -q "$id" "$ALIASLIST"; then
|
|
||||||
grep "$id" "$ALIASLIST" | cut -d' ' --complement -f1
|
|
||||||
else
|
|
||||||
grep "$id" "$PAIRLIST" | cut -d' ' --complement -f1,2
|
|
||||||
fi
|
|
||||||
done)"
|
|
||||||
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 'trust which paired device?')
|
choice=$( echo "$untrusted_devices" | dmenu -l 10 -i -p 'trust which paired device?')
|
||||||
@ -231,13 +222,7 @@ case $choice in
|
|||||||
#only list those connceted devices as options
|
#only list those connceted devices as options
|
||||||
# shellcheck disable=SC1091
|
# 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)"
|
||||||
connected_devices="$(echo "$connected_ids" | while read -r id; do
|
connected_devices="$( echo "$connected_ids" | de_alias )"
|
||||||
if grep -q "$id" "$ALIASLIST"; then
|
|
||||||
grep "$id" "$ALIASLIST" | cut -d' ' --complement -f1
|
|
||||||
else
|
|
||||||
grep "$id" "$PAIRLIST" | cut -d' ' --complement -f1,2
|
|
||||||
fi
|
|
||||||
done)"
|
|
||||||
#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
|
||||||
@ -259,7 +244,7 @@ case $choice in
|
|||||||
*)
|
*)
|
||||||
echo "choice: $choice"
|
echo "choice: $choice"
|
||||||
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}')
|
||||||
[ "$dev_no" != "" ] && dev_id=$( echo "$bt_IDS" | nl | grep -P "^.*$dev_no\t" | awk '{print $2}')
|
[ "$dev_no" != "" ] && dev_id=$( echo "$connected_ids" | nl | grep -P "^.*$dev_no\t" | awk '{print $2}')
|
||||||
echo "dev_id: $dev_id"
|
echo "dev_id: $dev_id"
|
||||||
if [ -n "$dev_id" ]; then
|
if [ -n "$dev_id" ]; then
|
||||||
power on
|
power on
|
||||||
|
Loading…
Reference in New Issue
Block a user