48 lines
1.3 KiB
Bash
Executable File
48 lines
1.3 KiB
Bash
Executable File
#!/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"
|
|
# }
|
|
|
|
# Make sure jq is installed
|
|
|
|
update_holder() {
|
|
local instance="$1"
|
|
local replacement="$2"
|
|
echo "$3" | jq --argjson arg_j "$replacement" "(.[] | (select(.instance==\"$instance\"))) |= \$arg_j"
|
|
}
|
|
|
|
remove_holder() {
|
|
local instance="$1"
|
|
echo "$2" | jq "del(.[] | (select(.instance==\"$instance\")))"
|
|
}
|
|
|
|
get_device_battery_status() {
|
|
for uuid in $(bluetoothctl devices | cut -f2 -d' ')
|
|
do
|
|
local device_info="$(bluetoothctl info "$uuid")"
|
|
|
|
if [ -n "$(echo $device_info | grep 'Connected: yes\|Battery Percentage')" ]; then
|
|
echo "$device_info" | grep 'Battery Percentage' | awk -F '[()]' '{ print "🎧🔋"$2"%" }'
|
|
break
|
|
fi
|
|
done
|
|
}
|
|
|
|
update_json_with_text() {
|
|
local json="{ \"full_text\": \"$1\", \"color\": \"#FFFFFF\"}"
|
|
update_holder holder__headphones "$json" "$2"
|
|
}
|
|
|
|
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/^,//')"
|
|
echo ",$(update_json_with_text "$(get_device_battery_status)" "$json_array")"
|
|
done)
|