mirror of
https://github.com/kmein/niveum
synced 2026-03-19 11:31:09 +01:00
feat(packages): improve dmenubluetooth
This commit is contained in:
@@ -1,22 +1,55 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# UI for connecting to bluetooth devices
|
# UI for connecting to bluetooth devices
|
||||||
|
set -efu
|
||||||
|
|
||||||
bluetooth_notify() {
|
bluetooth_notify() {
|
||||||
notify-send --app-name=" Bluetooth" "$@"
|
notify-send --app-name=" Bluetooth" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
bluetoothctl --timeout 1 -- scan on
|
chose_device() {
|
||||||
|
# the output from `bluetoothctl {paired-,}devices` has a first column which always contains `Device` followed by a MAC address and the device name
|
||||||
|
cut -d ' ' -f2- | dmenu -i -l 5 -p "Bluetooth device"
|
||||||
|
}
|
||||||
|
|
||||||
bluetooth_devices="$(bluetoothctl devices | cut -d ' ' -f2-)"
|
bluetoothctl scan on &
|
||||||
|
|
||||||
chosen="$(echo "$bluetooth_devices" | dmenu -i -l 5 -p "Bluetooth device")"
|
case "$(printf "pair\nconnect\ndisconnect" | dmenu -i)" in
|
||||||
chosen_name="$(echo "$chosen" | cut -d ' ' -f2-)"
|
pair)
|
||||||
|
chosen="$(bluetoothctl devices | chose_device)"
|
||||||
|
chosen_name="$(echo "$chosen" | cut -d ' ' -f2-)"
|
||||||
|
|
||||||
bluetooth_notify "$chosen_name" "Connecting ..."
|
bluetooth_notify "$chosen_name" "Pairing ..."
|
||||||
|
|
||||||
if bluetoothctl connect "$(echo "$chosen" | cut -d ' ' -f1)"
|
if bluetoothctl pair "$(echo "$chosen" | cut -d ' ' -f1)"; then
|
||||||
then
|
bluetooth_notify "✔ $chosen_name" "Paired with device."
|
||||||
bluetooth_notify "✔ $chosen_name" "Connected to device."
|
else
|
||||||
else
|
test "$chosen" && bluetooth_notify "❌ $chosen_name" "Failed to pair with device."
|
||||||
test "$chosen" && bluetooth_notify "❌ $chosen_name" "Failed to connect to device."
|
fi
|
||||||
fi
|
;;
|
||||||
|
|
||||||
|
connect)
|
||||||
|
chosen="$(bluetoothctl paired-devices | chose_device)"
|
||||||
|
chosen_name="$(echo "$chosen" | cut -d ' ' -f2-)"
|
||||||
|
|
||||||
|
bluetooth_notify "$chosen_name" "Trying to connect ..."
|
||||||
|
|
||||||
|
if bluetoothctl connect "$(echo "$chosen" | cut -d ' ' -f1)"; then
|
||||||
|
bluetooth_notify "✔ $chosen_name" "Connected to device."
|
||||||
|
else # something was selected but it didn't work
|
||||||
|
test "$chosen" && bluetooth_notify "❌ $chosen_name" "Failed to connect to device."
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
|
disconnect)
|
||||||
|
chosen="$(bluetoothctl paired-devices | chose_device)"
|
||||||
|
chosen_name="$(echo "$chosen" | cut -d ' ' -f2-)"
|
||||||
|
|
||||||
|
bluetooth_notify "$chosen_name" "Disconnecting ..."
|
||||||
|
|
||||||
|
if bluetoothctl disconnect "$(echo "$chosen" | cut -d ' ' -f1)"; then
|
||||||
|
bluetooth_notify "✔ $chosen_name" "Disconnected from device."
|
||||||
|
else # something was selected but it didn't work
|
||||||
|
test "$chosen" && bluetooth_notify "❌ $chosen_name" "Failed to disconnect from device."
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|||||||
Reference in New Issue
Block a user