From 8a613e438bce316adfa19fa392da95a9ccb21254 Mon Sep 17 00:00:00 2001 From: Eddy Pedroni Date: Sat, 21 Mar 2026 17:50:16 +0100 Subject: Add bluetooth indicator to statusbar --- dwm-statusbar | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/dwm-statusbar b/dwm-statusbar index 06803e3..90e3429 100755 --- a/dwm-statusbar +++ b/dwm-statusbar @@ -260,6 +260,29 @@ print_wlan() { echo -ne "${icon_colour}\uE401${wlan_colour}${wlan_ip} ${wlan_strength}%" } +print_bluetooth() { + bt_status=$(systemctl is-active bluetooth) + + if [[ "$bt_status" == "active" ]]; then + device_name=$(bluetoothctl info | grep Name: | sed -r 's/\s*Name: (.*?)/\1/g') + device_battery=$(bluetoothctl info | grep "Battery Percentage:" | sed -r 's/\s*Battery Percentage: .*?\(([0-9]+)\)/\1/g') + if [ $device_battery -lt 25 ]; then + icon_colour=${colour_critical} + battery_colour=${colour_critical} + elif [ $device_battery -lt 50 ]; then + icon_colour=${colour_warning} + battery_colour=${colour_warning} + else + icon_colour=${colour_neutral} + battery_colour=${colour_normal} + fi + echo -ne "${icon_colour}\uE212${battery_colour}${device_name} (${device_battery}%)" + else + icon_colour=${colour_faded} + echo -ne "${icon_colour}\uE212" + fi +} + while true; do # get new cpu idle and total usage eval $(awk '/^cpu /{print "cpu_idle_now=" $5 "; cpu_total_now=" $2+$3+$4+$5 }' /proc/stat) @@ -269,7 +292,7 @@ while true; do # Pipe to status bar # This is where you can adjust what gets shown by adding the desired function calls - xsetroot -name "$(print_eth)${space}$(print_wlan)${space}$(print_root_free)${space}$(print_home_free)${space}$(print_cpu_used)${space}$(print_cpu_temp)${space}$(print_mem_free)${space}$(print_battery)${space}$(print_backlight)${space}$(print_volume)${space}$(print_time)$(print_date)" + xsetroot -name "$(print_eth)${space}$(print_wlan)${space}$(print_bluetooth)${space}$(print_root_free)${space}$(print_home_free)${space}$(print_cpu_used)${space}$(print_cpu_temp)${space}$(print_mem_free)${space}$(print_battery)${space}$(print_backlight)${space}$(print_volume)${space}$(print_time)$(print_date)" # reset old rate cpu_idle_old=$cpu_idle_now -- cgit v1.2.3