From cfdb0952cab91324dc697d22e2fb310768c9eb64 Mon Sep 17 00:00:00 2001 From: TheK4n Date: Thu, 19 Jan 2023 21:55:20 +0300 Subject: [PATCH] i3status add headphones battery wrapper --- Makefile | 3 +- functions/i3status_wrapper.sh | 56 +++++++++++++++++++++++++++++++++++ sub/i3/config | 2 +- sub/i3/statusconfig | 44 ++++++++++++++++++--------- 4 files changed, 89 insertions(+), 16 deletions(-) create mode 100755 functions/i3status_wrapper.sh diff --git a/Makefile b/Makefile index 866b0a3..2ad88da 100644 --- a/Makefile +++ b/Makefile @@ -67,12 +67,13 @@ gpg: echo -e "default-cache-ttl 1\nmax-cache-ttl 1" > ~/.gnupg/gpg-agent.conf; echo RELOADAGENT | gpg-connect-agent i3: - @echo "sudo pacman -S nitrogen picom compton ttf-font-awesome xdotool xclip maim" + @echo "sudo pacman -S nitrogen picom jq compton ttf-font-awesome xdotool xclip maim" test -d ~/.config/i3 || \ mkdir -p ~/.config/i3 mkdir -p ~/.config/i3status ln -s $(PWD)/sub/i3/config ~/.config/i3/config ln -s $(PWD)/sub/i3/statusconfig ~/.config/i3status/config + ln -s $(PWD)/functions/i3status_wrapper.sh ~/.local/bin/i3status_wrapper.sh bat: test -d ~/.config/bat || \ diff --git a/functions/i3status_wrapper.sh b/functions/i3status_wrapper.sh new file mode 100755 index 0000000..76fb8ca --- /dev/null +++ b/functions/i3status_wrapper.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash + +# The idea is to define "holder" modules in i3status config and then replace them + +# In order to make this example work you need to add +# order += "tztime holder__headphones" +# and +# tztime holder__headphones { +# format = "holder__headphones" +# } +# in i3staus config + +# Don't forget that i3status config should contain: +# general { +# output_format = i3bar +# } +# +# and i3 config should contain: +# bar { +# status_command exec /path/to/this/script.sh +# } + +# Make sure jq is installed + +# You can easily add multiple custom modules using additional "holders" + +function update_holder { + + local instance="$1" + local replacement="$2" + echo "$json_array" | jq --argjson arg_j "$replacement" "(.[] | (select(.instance==\"$instance\"))) |= \$arg_j" +} + +function remove_holder { + + local instance="$1" + echo "$json_array" | jq "del(.[] | (select(.instance==\"$instance\")))" +} + +function headphones { + + battery_status="$(bluetoothctl info 14:0A:29:0A:6A:2F | grep "Battery Percentage" | awk -F '[()]' '{ print "🎧"$2"%" }')" + + local json="{ \"full_text\": \"$battery_status\", \"color\": \"#FFFFFF\"}" + + json_array=$(update_holder holder__headphones "$json") + +} + +i3status | (read line; echo "$line"; read line ; echo "$line" ; read line ; echo "$line" ; while true +do + read line + json_array="$(echo $line | sed -e 's/^,//')" + headphones + echo ",$json_array" +done) diff --git a/sub/i3/config b/sub/i3/config index fa6f70b..af9c233 100644 --- a/sub/i3/config +++ b/sub/i3/config @@ -198,7 +198,7 @@ bindsym $mod+r mode "resize" # Start i3bar to display a workspace bar (plus the system information i3status # finds out, if available) bar { - status_command i3status + status_command exec ~/.local/bin/i3status_wrapper.sh tray_output DP-0 } diff --git a/sub/i3/statusconfig b/sub/i3/statusconfig index 1137991..f088b31 100644 --- a/sub/i3/statusconfig +++ b/sub/i3/statusconfig @@ -7,8 +7,9 @@ # If the above line is not correctly displayed, fix your editor first! general { - colors = true - interval = 5 + colors = true + interval = 5 + output_format = i3bar } order += "ipv6" @@ -20,38 +21,40 @@ order += "disk /home" order += "memory" order += "cpu_usage" order += "cpu_temperature 0" +order += "tztime holder__headphones" +order += "volume master" order += "tztime local" wireless _first_ { - format_up = " (%quality at %essid) %ip" - format_down = " down" + format_up = " (%quality at %essid) %ip" + format_down = " down" } ethernet _first_ { - format_up = " %ip" - format_down = " down" + format_up = " %ip" + format_down = " down" } battery all { - format = " %status %percentage %remaining" + format = " %status %percentage %remaining" } disk "/" { - format = "/ %used/%total" + format = "/ %used/%total" } disk "/home" { - format = " %used/%total" + format = " %used/%total" } load { - format = "%1min" + format = "%1min" } memory { - format = "%used/%available" - threshold_degraded = "1G" - format_degraded = "MEMORY < %available" + format = "%used/%available" + threshold_degraded = "1G" + format_degraded = "MEMORY < %available" } cpu_usage { @@ -65,5 +68,18 @@ cpu_temperature 0 { } tztime local { - format = " %Y-%m-%d  %H:%M:%S" + format = " %Y-%m-%d  %H:%M:%S" +} + +volume master { + format = " %volume" # шаблон громкости в активном состоянии + format_muted = " %volume" # шаблон громкости в состоянии muted (без звука) + device = "default" + mixer = "Master" + mixer_idx = 0 +} + + +tztime holder__headphones { + format = "holder__headphones" }