diff options
| author | 0scar <qgt268@alumni.ku.dk> | 2020-10-21 15:51:56 +0000 |
|---|---|---|
| committer | 0scar <qgt268@alumni.ku.dk> | 2020-10-22 13:27:30 +0000 |
| commit | c4be0fe3c58fe07e235f624974b4f8102a17ecca (patch) | |
| tree | 83a7576319658278b73f579313f0a4f990e48f00 /.scripts/bt | |
| parent | 47bb601a722b294ac07c3f34b25ade8b1a06ecc3 (diff) | |
Add some neat scripts
Diffstat (limited to '.scripts/bt')
| -rwxr-xr-x | .scripts/bt | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/.scripts/bt b/.scripts/bt new file mode 100755 index 0000000..2e4203d --- /dev/null +++ b/.scripts/bt @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +set -e + +# Check if bluetooth is blocked +(rfkill | grep -E "bluetooth.*\<blocked\>" >/dev/null) && echo "Please check rfkill and unblock bluetooth module." && exit || true + +[ "$1" = "stop" ] && systemctl stop bluetooth.service && exit +systemctl is-active bluetooth.service >/dev/null || systemctl start bluetooth.service + +[ "$(bluetoothctl show | awk '/Powered/ {print $2}')" = "no" ] && bluetoothctl power on && bluetoothctl agent on + +BTID='^([A-F0-9]{2}:){5}[A-F0-9]{2}$' + +if [ $# -gt 0 ]; then + if [ "$#" -eq 1 ]; then + PAIRED=$(bluetoothctl paired-devices | grep "$1" | awk '/Device/ {print $2}') + + if [ $(echo "$1" | grep -E $BTID) ]; then bluetoothctl connect $1 + elif [ $(echo "$PAIRED" | grep -E $BTID) ]; then bluetoothctl connect $PAIRED + else bluetoothctl $* + fi + else bluetoothctl $* + fi +else + CONNECTED="$(bluetoothctl info | awk '/Name/ {print $2}')" || true + + bluetoothctl paired-devices | awk "/Device/ {if(\"$CONNECTED\"==\$3) print \"\033[1;32m\" \$2 \"\t\" \$3 \"\033[0m\"; else print \$2 \"\t\" \$3;}" +fi |
