added alias file

This commit is contained in:
Alexander Bocken 2021-06-28 20:10:16 +02:00
parent 11689c2e22
commit b77d701595
Signed by: Alexander
GPG Key ID: 1D237BE83F9B05E8
2 changed files with 20 additions and 4 deletions

View File

@ -16,6 +16,7 @@ install:
chmod 755 $(DESTDIR)/bt
touch $(DATA_DIR)/blacklist
touch $(DATA_DIR)/paired
touch $(DATA_DIR)/alias
uninstall:
rm -f $(DESTDIR)/bt
@ -27,5 +28,6 @@ clear:
mkdir -p $(DATA_DIR)
touch $(DATA_DIR)/paired
touch $(DATA_DIR)/blacklist
touch $(DATA_DIR)/alias
.PHONY: install uninstall clear

22
bt
View File

@ -9,6 +9,7 @@ barsignal="4"
#locations of blacklist and hard coded list of paired devices (watch out, need to modify Makefile as well if you want to change these values and still use make install)
BLACKLIST=${XDG_DATA_HOME:-$HOME/.local/share}/bt/blacklist
PAIRLIST=${XDG_DATA_HOME:-$HOME/.local/share}/bt/paired
ALIASLIST=${XDG_DATA_HOME:-$HOME/.local/share}/bt/alias
actions="$(printf 'pair\nunpair\n')"
@ -79,10 +80,12 @@ startup(){
if [ "$1" = "edit" ]; then
case $2 in
"pairlist")${EDITOR:-vim} "$PAIRLIST" && exit;;
"blacklist")${EDITOR:-vim} "$BLACKLIST" && exit;;
"pairlist")${EDITOR:-vim} "$PAIRLIST";;
"blacklist")${EDITOR:-vim} "$BLACKLIST";;
"aliaslist")${EDITOR:-vim} "$ALIASLIST";;
*)true;;
esac
exit
fi
#Sadly needs to be run without '&' for now, since it otherwise breaks start_scan variable
startup &
@ -97,10 +100,21 @@ fi
#Compile list of all Bluetooth IDS of paired devices (from bluetoothctl and from hardcoded list)
bt_IDS="$( ( bluetoothctl paired-devices && cat "$PAIRLIST" ) | sort -u | awk '{print $2}' )"
bt_IDS="$( ( bluetoothctl paired-devices && cat "$PAIRLIST" ) | awk '{print $2}' | sort -u )"
#Compile list of all device Names of paired devices (from bluetoothctl and from hardcoded list)
paired_devices="$( ( bluetoothctl paired-devices && cat "$PAIRLIST" ) | sort -u | awk '{for (i=3; i<NF; i++) printf $i " "; print $NF}' )"
paired_devices_with_id="$( ( bluetoothctl paired-devices && cat "$PAIRLIST" ) | sort -u | awk '{for (i=2; i<NF; i++) printf $i " "; print $NF}' )"
#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)"
#paired_devices="$( ( bluetoothctl paired-devices && cat "$PAIRLIST" ) | sort -u | awk '{for (i=3; i<NF; i++) printf $i " "; print $NF}' )"
echo "paired_devices:$paired_devices"
disp_devices="$( echo "$paired_devices" | grep -vf "$BLACKLIST" )"