From 1c6bac78822bf4cb3371eca8345661406ccda357 Mon Sep 17 00:00:00 2001 From: Shubham Saini Date: Fri, 12 Nov 2021 18:40:53 -0800 Subject: added bt to polybar --- polybar/.config/polybar/bt.sh | 64 ++++++++++++++++++++++++++++++++++++++++++ polybar/.config/polybar/config | 11 +++++++- 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100755 polybar/.config/polybar/bt.sh (limited to 'polybar') diff --git a/polybar/.config/polybar/bt.sh b/polybar/.config/polybar/bt.sh new file mode 100755 index 0000000..f754059 --- /dev/null +++ b/polybar/.config/polybar/bt.sh @@ -0,0 +1,64 @@ +#!/bin/sh + +bluetooth_print() { + bluetoothctl | while read -r; do + if [ "$(systemctl is-active "bluetooth.service")" = "active" ]; then + # printf 'on' + + devices_paired=$(bluetoothctl paired-devices | grep Device | cut -d ' ' -f 2) + counter=0 + + for device in $devices_paired; do + device_info=$(bluetoothctl info "$device") + + if echo "$device_info" | grep -q "Connected: yes"; then + device_alias=$(echo "$device_info" | grep "Alias" | cut -d ' ' -f 2-) + + if [ $counter -gt 0 ]; then + printf ", %s" "$device_alias" + else + printf " %s" "$device_alias" + fi + + counter=$((counter + 1)) + elif bluetoothctl show | grep -q "Powered: yes"; then + printf "disconnected" + else + printf "off" + fi + done + + printf '\n' + else + echo "off" + fi + done +} + +bluetooth_toggle() { + if bluetoothctl show | grep -q "Powered: no"; then + bluetoothctl power on >> /dev/null + sleep 1 + + devices_paired=$(bluetoothctl paired-devices | grep Device | cut -d ' ' -f 2) + echo "$devices_paired" | while read -r line; do + bluetoothctl connect "$line" >> /dev/null + done + else + devices_paired=$(bluetoothctl paired-devices | grep Device | cut -d ' ' -f 2) + echo "$devices_paired" | while read -r line; do + bluetoothctl disconnect "$line" >> /dev/null + done + + bluetoothctl power off >> /dev/null + fi +} + +case "$1" in + --toggle) + bluetooth_toggle + ;; + *) + bluetooth_print + ;; +esac diff --git a/polybar/.config/polybar/config b/polybar/.config/polybar/config index b5c486a..477fa30 100755 --- a/polybar/.config/polybar/config +++ b/polybar/.config/polybar/config @@ -33,7 +33,7 @@ module-margin-left = 1.5 module-margin-right = 1.5 font-0 = Input Mono:style=medium:size=10:antialias=true:autohint=true:lcdfilter=lcddefault:rgba=rgb font-1 = JetBrains Mono Nerd Font Mono:style=medium:size=10:antialias=true:autohint=true:lcdfilter=lcddefault:rgba=rgb -modules-left = pulseaudio battery date time cmus +modules-left = pulseaudio battery date time bt cmus modules-center = modules-right = bspwm tray-position = right @@ -181,3 +181,12 @@ bar-progress-width = 10 bar-progress-indicator = | bar-progress-fill = ─ bar-progress-empty = ─ + +[module/bt] +type = custom/script +exec = ~/.config/polybar/bt.sh +tail = true +click-left = ~/.config/polybar/bt.sh --toggle & +format = tooth