Bluetooth dmenu

This commit is contained in:
Tobias Manske 2019-10-26 02:20:03 +02:00
parent ad614bbce9
commit 0de0f05cd0
No known key found for this signature in database
GPG Key ID: 978D99F12D4E041F
2 changed files with 42 additions and 1 deletions

View File

@ -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

38
i3/scripts/dmenu_bt.sh Executable file
View File

@ -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