Converted script to bash instead of needing zsh, cleaned up a bit.

This commit is contained in:
Alexander Bocken 2020-04-18 22:31:45 +02:00
parent 3502382e05
commit 0b9421af97
2 changed files with 12 additions and 11 deletions

View File

@ -1,10 +1,10 @@
# bthandler # bthandler
# See LICENSE file for copyright and license details. # See LICENSE file for copyright and license details.
VERSION = 1.0 VERSION = 1.1
# paths # paths
PREFIX = ~/.local/bin PREFIX = ~/.local/bin/tools
SRC = bthandler SRC = bthandler
OBJ = $(SRC:.c=.o) OBJ = $(SRC:.c=.o)

View File

@ -1,32 +1,33 @@
#!/bin/zsh #!/bin/bash
#wait time to discover new devices in seconds #wait time to discover new devices in seconds
SCAN_PERIOD=5 SCAN_PERIOD=5
BLACKLIST=$HOME/.local/bin/tools/bt_blacklist
IDS=$(bluetoothctl paired-devices | awk '{print $2}') IDS=$(bluetoothctl paired-devices | awk '{print $2}')
echo $IDS > /tmp/bt_IDS echo $IDS > /tmp/bt_IDS
Devices=$(bluetoothctl paired-devices | awk '{for (i=3; i<NF; i++) printf $i " "; print $NF}' | sed 's/ $//') Devices=$(bluetoothctl paired-devices | awk '{for (i=3; i<NF; i++) printf $i " "; print $NF}' | sed 's/ $//')
echo $Devices > /tmp/bt_devices echo $Devices > /tmp/bt_devices
Blacklist='MX Master\n'
Devices=$( echo $Devices | grep -vf $BLACKLIST )
actions="\nturn off\nturn on\nscan on\npair" actions="\nturn off\nturn on\nscan on\npair"
choice=$( echo $Devices$actions | dmenu -p 'BT:' ) choice=$( printf "$Devices$actions" | dmenu -i -p 'What BT action would you like to perform:' )
cleanup(){ cleanup(){
rm -f /tmp/bt_devices rm -f /tmp/bt_devices
rm -f /tmp/bt_IDS rm -f /tmp/bt_IDS
rm -f /tmp/paired_devices rm -f /tmp/paired_devices
exit
} }
case $choice in case $choice in
"turn on") bluetoothctl power on "turn on") bluetoothctl power on
cleanup cleanup;;
exit;;
"turn off") bluetoothctl power off "turn off") bluetoothctl power off
cleanup cleanup;;
exit;;
"scan on") bluetoothctl power on && echo power on && sleep 2 "scan on") bluetoothctl power on && echo power on && sleep 2
st -e bluetoothctl scan on st -e bluetoothctl scan on
cleanup cleanup;;
exit;;
"pair") bluetoothctl power on "pair") bluetoothctl power on
bluetoothctl scan on & disown bluetoothctl scan on & disown
notify-send "Bluetooth" "Searching for devices, please wait a bit" notify-send "Bluetooth" "Searching for devices, please wait a bit"