Last active
November 15, 2023 22:24
-
-
Save SmallEndian/9846454cd7d630abb7580a046459720e to your computer and use it in GitHub Desktop.
Rofi - bluetoothctl choice
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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