fix(i3status_wrapper): timeout for bluetoothctl

This commit is contained in:
TheK4n 2023-10-24 23:20:54 +03:00
parent a200c7d445
commit 5f6d518c2c
3 changed files with 16 additions and 12 deletions

View File

@ -3,6 +3,8 @@ exec --no-startup-id ~/.screenlayout/default.sh
set $SecMon "HDMI-0"
for_window [tiling] border pixel 3
smart_borders on
set $mod Mod4
exec --no-startup-id xset s off
@ -180,7 +182,6 @@ bindsym $mod+Shift+e exec "i3-nagbar -t warning -m 'You pressed the exit shortcu
# finds out, if available)
bar {
output primary
output nonprimary
tray_output primary
status_command exec ~/.local/bin/i3status_wrapper
}

View File

@ -8,7 +8,7 @@
general {
colors = true
interval = 5
interval = 2
output_format = i3bar
}

View File

@ -9,7 +9,7 @@
# format = "holder__headphones"
# }
# Make sure jq is installed
[ -x "/usr/bin/jq" ] || exec i3status
update_holder() {
local instance="$1"
@ -23,11 +23,12 @@ remove_holder() {
}
get_device_battery_status() {
for uuid in $(bluetoothctl devices | cut -f2 -d' ')
for uuid in $(timeout 1 bluetoothctl devices | cut -f2 -d' ' 2>/dev/null)
do
local device_info="$(bluetoothctl info "$uuid")"
local device_info
device_info="$(timeout 1 bluetoothctl info "$uuid")"
if [ -n "$(echo $device_info | grep 'Connected: yes\|Battery Percentage')" ]; then
if echo "$device_info" | grep -q 'Connected: yes\|Battery Percentage'; then
echo "$device_info" | grep 'Battery Percentage' | awk -F '[()]' '{ print "🎧🔋"$2"%" }'
break
fi
@ -39,9 +40,11 @@ update_json_with_text() {
update_holder holder__headphones "$json" "$2"
}
i3status | (read line; echo "$line"; read line ; echo "$line" ; read line ; echo "$line" ; while true
i3status | (read -r line; echo "$line"; read -r line; echo "$line";
while true
do
read line
json_array="$(echo $line | sed -e 's/^,//')"
read -r line
json_array="$(echo "$line" | sed -e 's/^,//')"
echo ",$(update_json_with_text "$(get_device_battery_status)" "$json_array")"
done)
done
)