i3status add headphones battery wrapper

This commit is contained in:
TheK4n 2023-01-19 21:55:20 +03:00
parent da64c088f7
commit cfdb0952ca
4 changed files with 89 additions and 16 deletions

View File

@ -67,12 +67,13 @@ gpg:
echo -e "default-cache-ttl 1\nmax-cache-ttl 1" > ~/.gnupg/gpg-agent.conf; echo RELOADAGENT | gpg-connect-agent echo -e "default-cache-ttl 1\nmax-cache-ttl 1" > ~/.gnupg/gpg-agent.conf; echo RELOADAGENT | gpg-connect-agent
i3: 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 || \ test -d ~/.config/i3 || \
mkdir -p ~/.config/i3 mkdir -p ~/.config/i3
mkdir -p ~/.config/i3status mkdir -p ~/.config/i3status
ln -s $(PWD)/sub/i3/config ~/.config/i3/config ln -s $(PWD)/sub/i3/config ~/.config/i3/config
ln -s $(PWD)/sub/i3/statusconfig ~/.config/i3status/config ln -s $(PWD)/sub/i3/statusconfig ~/.config/i3status/config
ln -s $(PWD)/functions/i3status_wrapper.sh ~/.local/bin/i3status_wrapper.sh
bat: bat:
test -d ~/.config/bat || \ test -d ~/.config/bat || \

56
functions/i3status_wrapper.sh Executable file
View File

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

View File

@ -198,7 +198,7 @@ bindsym $mod+r mode "resize"
# Start i3bar to display a workspace bar (plus the system information i3status # Start i3bar to display a workspace bar (plus the system information i3status
# finds out, if available) # finds out, if available)
bar { bar {
status_command i3status status_command exec ~/.local/bin/i3status_wrapper.sh
tray_output DP-0 tray_output DP-0
} }

View File

@ -9,6 +9,7 @@
general { general {
colors = true colors = true
interval = 5 interval = 5
output_format = i3bar
} }
order += "ipv6" order += "ipv6"
@ -20,6 +21,8 @@ order += "disk /home"
order += "memory" order += "memory"
order += "cpu_usage" order += "cpu_usage"
order += "cpu_temperature 0" order += "cpu_temperature 0"
order += "tztime holder__headphones"
order += "volume master"
order += "tztime local" order += "tztime local"
wireless _first_ { wireless _first_ {
@ -67,3 +70,16 @@ cpu_temperature 0 {
tztime local { 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"
}