|
|
|
@ -1,9 +1,25 @@ |
|
|
|
|
#!/usr/bin/env sh |
|
|
|
|
|
|
|
|
|
connect() { |
|
|
|
|
if bluetoothctl info "$1" | grep Connected | grep -q no; then |
|
|
|
|
bluetoothctl discoverable on |
|
|
|
|
if bluetoothctl info "$1" | grep Paired | grep -q no; then |
|
|
|
|
bluetoothctl pairable on |
|
|
|
|
notify-send "Pairing with $1..." |
|
|
|
|
bluetoothctl --timeout=10 pair "$1" || notify-send "Pairing failed" && return |
|
|
|
|
bluetoothctl trust "$1" || notify-send "Trusting failed" && return |
|
|
|
|
fi |
|
|
|
|
bluetoothctl --timeout=5 connect "$1" || notify-send "Connecting failed" && return |
|
|
|
|
fi |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
devicemenu() { |
|
|
|
|
if bluetoothctl show | grep Powered | grep -q no; then |
|
|
|
|
bluetoothctl power on |
|
|
|
|
fi |
|
|
|
|
while true; do |
|
|
|
|
DEVICES="$(bluetoothctl devices | awk '{ $1=""; printf $2; $2=""; printf " ^" $0 "\n" }')" |
|
|
|
|
ENTRIES="$(echo "$DEVICES" | sed 's|.* ^ ||' | xargs -0 printf "Close Menu\nDisconnect\n%s")" |
|
|
|
|
ENTRIES="$(echo "$DEVICES" | sed 's|.* ^ ||' | xargs -0 printf "Close Menu\nDisconnect\nScan\n%s")" |
|
|
|
|
|
|
|
|
|
PICKED="$( |
|
|
|
|
echo "$ENTRIES" | |
|
|
|
@ -14,12 +30,20 @@ devicemenu() { |
|
|
|
|
exit |
|
|
|
|
elif echo "$PICKED" | grep -q "Disconnect"; then |
|
|
|
|
st -e sh -c "bluetoothctl disconnect; sleep 1" |
|
|
|
|
continue |
|
|
|
|
elif echo "$PICKED" | grep -q "Scan"; then |
|
|
|
|
notify-send "Scanning BT devices for 5 seconds..." |
|
|
|
|
bluetoothctl --timeout=5 scan on |
|
|
|
|
else |
|
|
|
|
devicemac="$(echo "$DEVICES" | grep " \^ $PICKED$" | sed 's| ^ .*||' )" |
|
|
|
|
st -e sh -c "bluetoothctl connect $devicemac; sleep 1" |
|
|
|
|
st -e sh -c "$0 connect $devicemac" |
|
|
|
|
bluetoothctl pairable off |
|
|
|
|
bluetoothctl discoverable off |
|
|
|
|
fi |
|
|
|
|
done |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
devicemenu |
|
|
|
|
if [ -n "$1" ]; then |
|
|
|
|
"$@" |
|
|
|
|
else |
|
|
|
|
devicemenu |
|
|
|
|
fi |
|
|
|
|