diff --git a/README.md b/README.md index e8ee7dd..317693e 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,8 @@ Edit the Makefile to reflect your preffered installation destination. Then, simp make install ``` +**Note:** If you don't change the Makefile `sudo` is not required and might break the blacklist and hardcoded pair list. + Afterwards, invoking `bt` will start the menu. # Clear blacklist/pairlist @@ -26,27 +28,24 @@ Afterwards, invoking `bt` will start the menu. Since `bluetoothctl paired-devices` seems to be hugely unreliable in listing paired devices, bthandler has a seperate list for all devices paired through bthandler. There is also a blacklist available to not display certain devices, which might be useful for autoconnection Bluetooth mice for example. -**Note:** If for some reason `bluetoothctl paired-devices` works for you dont worry, bthandler lists all devices returned from `bluetoothctl` and it's own paired devices list. (Duplicates are not displayed.) - To clear these files, simply run ```bash make clear ``` and these files will be reset to their inital, empty state. +**Note:** If for some reason `bluetoothctl paired-devices` works for you dont worry, bthandler lists all devices returned from `bluetoothctl` and it's own paired devices list. (Duplicates are not displayed.) + # Uninstall To uninstall you might follow that it's a simple ```bash make uninstall ``` -**Watch out:** since I'm using relative paths in the Makefile, it does make a difference whether you run the script with sudo or without. (both will work, you just have to be consistent in the installing und unisntalling process) If you have troubles with an uninstall, _additionally_ run `which bt | xargs rm`. # TODO -Here's a growing list of features that are not yet actively worked on but might be nice in the future. Currently I'm more concerned with reliability than fulfilling feature requests, but I'm still open to put some on this list. - - start scanning for new devices immediately at execution to save time when pairing new devices -> **Implemented** - auto-trust newly paired devices/trust device via dmenu -> **Implemented changeable via the AUTOTRUST variable in the beginning of bt, menu display adjusts accordingly** - blacklist devices via dmenu -> **Implemented** (action is hidden, but typing `blacklist` as your choice will reveal the menu) diff --git a/bt b/bt deleted file mode 100755 index ac36192..0000000 --- a/bt +++ /dev/null @@ -1,188 +0,0 @@ -#!/bin/sh -SCAN_PERIOD=5 -AUTOTRUST=false -AUTOSCAN=true #immediately start scanning when started to speed up pairing process -#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 - -actions="pair -unpair" - -[ "$AUTOTRUST" = false ] && actions="${actions} -trust" - -#Checks for necessary programs to be present. Very unlikely not to be present but let's just err on the safer side. -for prog in dmenu bluetoothctl awk cat date nl; do - if ! hash "$prog" 2>/dev/null; then - printf 'bthandler: %s: command not found\n' "$prog" >&2 - exit 127 - fi -done - -power(){ - powerstatus="$( bluetoothctl show | grep Powered | awk '{print $2}' )" - [ "$powerstatus" = "no" ] && [ "$1" = on ] && bluetoothctl power on - [ "$powerstatus" = "yes" ] && [ "$1" = off ] && bluetoothctl power off -} -scan(){ - scanstatus="$( bluetoothctl show | grep Discovering | awk '{print $2}' )" - if [ "$1" = on ]; then - #sets variable in case scanning was already on before the start of bt - [ "$start_scan" = "" ] && start_scan="$( date +'%s' )" - if [ "$scanstatus" = "no" ]; then - bluetoothctl scan on & - start_scan="$( date +'%s' )" - fi - elif [ "$1" = off ]; then - if [ "$scanstatus" = "yes" ]; then - bluetoothctl scan off - fi - fi -} - -#Check bluetoothctl paired-devices for new devices to be hardcoded into pair list -update_pair_list(){ - btctl_paired_devices="$(bluetoothctl paired-devices)" - if [ -n "$btctl_paired_devices" ] - then - btctl_not_in_list="$( echo "$btctl_paired_devices" | grep -vf "$PAIRLIST")" - [ -n "$btctl_not_in_list" ] && echo "$btctl_not_in_list" >> "$PAIRLIST" - fi -} - - -#start scanning as early as possible to speed up pairing process -#=> maybe use an option to do this? Otherwise ever invocation of bt powers on the controller. -if $AUTOSCAN -then - power on - scan on -fi -update_pair_list & - -# shellcheck disable=SC1091 -if bluetoothctl devices | awk '{print "bluetoothctl info "$2}' | . /dev/stdin | grep -q "Connected: yes" -then - actions="$(printf "disconnect\n%s" "$actions")" -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}' )" - -#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 /tmp/paired_devices$$ - filtered_devices="$( echo "$all_devices" | grep -vf "/tmp/paired_devices$$")" - bt_IDS="$( echo "$filtered_devices" | awk '{print $2}' )" - new_devices="$( echo "$filtered_devices" | awk '{for (i=3; i> "$PAIRLIST" - fi - fi - fi -} - -case $choice in - "power on") bluetoothctl power on;; - "power off") bluetoothctl power off;; - "scan on") bluetoothctl power on && echo power on && sleep 2 - ([ -n "$TERMINAL" ] && $TERMINAL -e bluetoothctl scan on ) || st bluetoothctl scan on;; - "pair") pair;; - "unpair") choice=$( echo "$paired_devices" | dmenu -l 10 -i -p 'remove which paired device?') - 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}' ) - bluetoothctl remove "$dev_id" - #remove device to unpair from hard coded paired devices list - new_paired_list="$( grep -v "$dev_id" "$PAIRLIST" )" - if [ "$new_paired_list" != "" ] - then - echo "$new_paired_list" > "$PAIRLIST" - else - rm -rf "$PAIRLIST" - touch "$PAIRLIST" - fi - fi;; - "trust") choice=$( echo "$paired_devices" | dmenu -l 10 -i -p 'remove which paired device?') - 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}' ) - bluetoothctl trust "$dev_id" - fi;; - "disconnect") choice=$( echo "$paired_devices" | dmenu -l 10 -i -p 'remove which paired device?') - 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}' ) - bluetoothctl disconnect "$dev_id" - fi;; - "blacklist") - choice=$( echo "$paired_devices" | dmenu -l 10 -i -p 'blacklist which paired device from selection?') - if [ -n "$choice" ]; then - echo "$choice" >> "$BLACKLIST" - fi;; - *) - echo "$choice" - 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}') - if [ -n "$dev_id" ]; then - power on - bluetoothctl pair "$dev_id" - bluetoothctl connect "$dev_id" - fi;; -esac