nixos-config/scripts/auto_connect_gamepad

28 lines
714 B
Plaintext
Raw Normal View History

2024-05-30 21:48:43 -03:00
#!/bin/sh
list_paired_controllers() {
2024-07-01 10:26:37 -03:00
bluetoothctl devices Paired | grep 'Controller' | cut -d' ' -f2
2024-05-30 21:48:43 -03:00
}
count_connected_controllers() {
2024-07-01 10:26:37 -03:00
bluetoothctl devices Connected | grep 'Controller' | wc -l
2024-05-30 21:48:43 -03:00
}
try_to_connect_to_all_controllers() {
list_paired_controllers | while read paired_controller; do
echo "Trying to connect to controller $paired_controller"
bluetoothctl connect "$paired_controller"
done
}
while true; do
echo "looping"
if test "$(count_connected_controllers)" -ne 0 ; then
echo "there is a controller connected, not attempting to connect to any other"
sleep 10s
continue
fi
2024-06-16 13:54:10 -03:00
sleep 1s
2024-05-30 21:48:43 -03:00
try_to_connect_to_all_controllers
done