From 0de0f05cd0f7edc0aee8a762cb157c0ec8963dc2 Mon Sep 17 00:00:00 2001 From: Tobias Manske Date: Sat, 26 Oct 2019 02:20:03 +0200 Subject: [PATCH] Bluetooth dmenu --- i3/conf/common/base | 5 ++++- i3/scripts/dmenu_bt.sh | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100755 i3/scripts/dmenu_bt.sh diff --git a/i3/conf/common/base b/i3/conf/common/base index 071eab6..ebecfce 100644 --- a/i3/conf/common/base +++ b/i3/conf/common/base @@ -46,6 +46,9 @@ floating_modifier $mod bindsym $mod+Return exec $TERMINAL bindsym $mod+Shift+Return exec $TERMINAL -name forced_term + # bluetooth dmenu + bindsym $mod+b exec ~/.dotfiles/i3/scripts/dmenu_bt.sh + # kill focused window bindsym $mod+Shift+q kill @@ -200,6 +203,6 @@ floating_modifier $mod gaps outer $gap_outer # {{{ NO BORDERS }}} - default_border pixel + default_border none default_floating_border normal diff --git a/i3/scripts/dmenu_bt.sh b/i3/scripts/dmenu_bt.sh new file mode 100755 index 0000000..f536930 --- /dev/null +++ b/i3/scripts/dmenu_bt.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +declare -a menu +declare -A commands +export POWERED=0 + +if bluetoothctl show | grep "Powered: yes"; then + menu+=("power off") + commands["power off"]="bluetoothctl power off" + # menu+=("Scan for new devices") + # commands["Scan for new devices"]="bluetoothctl scan on" + POWERED=1 +else + menu+=("power on") + commands["power on"]="bluetoothctl power on" +fi + +if [ $POWERED -eq 1 ]; then + IFS=$'\n' + for i in $(bluetoothctl paired-devices); do + # echo $i + if bluetoothctl info $(echo "$i" | cut -d" " -f2) | grep "Connected: yes"; then + TEXT="Disconnect from $(echo "$i" | cut -d" " -f3)" + CMD="bluetoothctl disconnect $(echo "$i" | cut -d" " -f2)" + else + TEXT="Connect to $(echo "$i" | cut -d" " -f3)" + CMD="bluetoothctl connect $(echo "$i" | cut -d" " -f2)" + fi + menu+=("$TEXT") + commands["$TEXT"]="$CMD" + done +fi + +RETVAL=$(for index in "${!menu[@]}"; do echo "${menu[$index]}"; done | dmenu -l 5 -p "Bluetooth") +if [ $? ]; then + RETCMD=${commands["$RETVAL"]} + echo $RETCMD | bash +fi