refactor(i3status_wrapper)
This commit is contained in:
parent
1726434b53
commit
c88c4f56fd
@ -8,55 +8,40 @@
|
||||
# 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 {
|
||||
|
||||
update_holder() {
|
||||
local instance="$1"
|
||||
local replacement="$2"
|
||||
echo "$json_array" | jq --argjson arg_j "$replacement" "(.[] | (select(.instance==\"$instance\"))) |= \$arg_j"
|
||||
echo "$3" | jq --argjson arg_j "$replacement" "(.[] | (select(.instance==\"$instance\"))) |= \$arg_j"
|
||||
}
|
||||
|
||||
function remove_holder {
|
||||
|
||||
remove_holder() {
|
||||
local instance="$1"
|
||||
echo "$json_array" | jq "del(.[] | (select(.instance==\"$instance\")))"
|
||||
echo "$2" | jq "del(.[] | (select(.instance==\"$instance\")))"
|
||||
}
|
||||
|
||||
function headphones {
|
||||
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
|
||||
battery_status="$(echo "$device_info" | grep 'Battery Percentage' | awk -F '[()]' '{ print "🎧🔋"$2"%" }')"
|
||||
local json="{ \"full_text\": \"$battery_status\", \"color\": \"#FFFFFF\"}"
|
||||
json_array=$(update_holder holder__headphones "$json")
|
||||
echo "$device_info" | grep 'Battery Percentage' | awk -F '[()]' '{ print "🎧🔋"$2"%" }'
|
||||
break
|
||||
fi
|
||||
done
|
||||
local json="{ \"full_text\": \"No headphones\", \"color\": \"#FFFFFF\"}"
|
||||
json_array=$(update_holder holder__headphones "$json")
|
||||
}
|
||||
|
||||
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/^,//')"
|
||||
headphones
|
||||
echo ",$json_array"
|
||||
echo ",$(update_json_with_text "$(get_device_battery_status)" "$json_array")"
|
||||
done)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user