Created
September 17, 2025 19:47
-
-
Save chrisnew/70160c45610ee79e66a22bededdad5cd to your computer and use it in GitHub Desktop.
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 bash | |
| set -e | |
| function _menu { | |
| bluetoothctl devices | awk '{ print $2 }' | while read -r MAC; do | |
| INFO="$(bluetoothctl info "$MAC")" | |
| printf "%s %-6s %s\n" \ | |
| "$MAC" \ | |
| "$(echo "$INFO" | awk '/Connected: no/ { print "" } /Connected: yes/ { print "ON" }')" \ | |
| "$(echo "$INFO" | awk '/Name:/ { gsub(/^\s+Name:\s+/, "", $0); print $0 }')" | |
| done | |
| } | |
| SELECTION=$(_menu | rofi -dmenu -p "Connect/disconnect a device" -no-custom \ | |
| -line-margin 0 -line-padding 1 \ | |
| -separator-style none -font "mono 10" -columns 1 -bw 0 \ | |
| -disable-history \ | |
| -hide-scrollbar \ | |
| -color-window "#cc222222, #ff222222, #ccb1b4b3" \ | |
| -color-normal "#00222222, #b1b4b3, #00222222, #ff005577, #b1b4b3" \ | |
| -color-active "#00222222, #b1b4b3, #00222222, #ff007763, #b1b4b3" \ | |
| -color-urgent "#00222222, #b1b4b3, #00222222, #ff77003d, #b1b4b3" ) | |
| if [ -n "$SELECTION" ]; then | |
| MAC="$(echo "$SELECTION" | awk '{ print $1 }')" | |
| case "$(echo "$SELECTION" | awk '{ print $2 }')" in | |
| "ON") | |
| bluetoothctl disconnect "$MAC" | |
| ;; | |
| *) | |
| bluetoothctl connect "$MAC" | |
| ;; | |
| esac | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment