Skip to content

Instantly share code, notes, and snippets.

@SmallEndian
Last active November 15, 2023 22:24
Show Gist options
  • Select an option

  • Save SmallEndian/9846454cd7d630abb7580a046459720e to your computer and use it in GitHub Desktop.

Select an option

Save SmallEndian/9846454cd7d630abb7580a046459720e to your computer and use it in GitHub Desktop.
Rofi - bluetoothctl choice
#!/usr/bin/env -S bash -e
# This script is meant to be called through rofi
# Hopefully as an element of polybar
# Polybar config
#
# rofi -show bt -modes "bt:bt-choice.sh"
#
# [module/bt]
# type = custom/script
# expand-right=true
# exec = echo "Bt $(bluetoothctl devices Connected | wc -l)"
# interval=360
# click-left= rofi -show bt -modes "bt:bt-choice.sh"
function set_option() {
echo -en "\0$1\x1f$2\n"
}
if ! which bluetoothctl > /dev/null
then
echo "bluetoothctl must be installed"
exit 1
fi
devices=$(bluetoothctl devices Paired | cut -d' ' -f2,3)
if [ 0 -eq $# ]
then
echo "There were no arguments" >&2
set_option "prompt" "Choose a device"
IFS='\n'
for i in "$devices"
do
echo $i
done
else
bluetoothctl connect $(echo $1 | cut -d' ' -f1) >/dev/null &
disown
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment