From 66c5e54c6a82912315f0442b8b8911536ea31f62 Mon Sep 17 00:00:00 2001 From: James Patrick Date: Mon, 10 Jun 2019 00:13:13 -0400 Subject: [PATCH] Added Bluetooth rofi controller This was lifted from: https://github.com/japorized/bin/blob/master/rofi-btctl --- rofi/scripts/btctl | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 rofi/scripts/btctl diff --git a/rofi/scripts/btctl b/rofi/scripts/btctl new file mode 100755 index 0000000..2da5d6b --- /dev/null +++ b/rofi/scripts/btctl @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +# cmds=($(bluetoothctl help | cut -d' ' -f1 | sed 's/[\x01-\x1F\x7F]//g' | sed 's/\[[0-9];[0-9]\+m//g')) +# unset "cmds[2]" +# unset "cmds[1]" +# unset "cmds[0]" +cmds=(list devices power connect disconnect) + +case $1 in + h|help|-h|--help) + echo `This is a simple rofi script to connect to trusted devices.` + exit 0 + ;; +esac + +_rofi() { + if [ -n "$1" ] ; then + rofi -dmenu -i -theme applet -p "Bluetooth" -mesg "$1" + else + rofi -dmenu -i -theme applet -p "Bluetooth" + fi +} + +choice=$(printf '%s\n' "${cmds[@]}" | _rofi) + +case "$choice" in + list|devices) + bluetoothctl ${choice} | _rofi "bluetoothctl $choice" + ;; + connect|disconnect) + device=$(bluetoothctl devices | _rofi "bluetoothctl list") + device=$(echo $device | cut -d' ' -f2) + bluetoothctl ${choice} ${device} && notify-send "Bluetoothctl" "${choice}ed from ${device}" + ;; + power) + onoff=(on off) + ans=$(printf '%s\n' "${onoff[@]}" | _rofi "bluetoothctl power") + bluetoothctl power ${ans} && notify-send "Bluetoothctl" "Power $ans" + ;; + *) +esac