Skip to content

Commit

Permalink
Prevent errors from qubes-i3status
Browse files Browse the repository at this point in the history
line 111 [...] syntax error  operand expected (error token is "- ")
line 68 [...] division by 0 (error token is "accum_full_mWh")
  • Loading branch information
imme-emosol authored Mar 29, 2023
1 parent b1e3762 commit 87649d0
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions qubes-i3status
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ status_time() {
}

status_bat() {
local accum_now_mWh=0 # current battery power in mWh
local accum_full_mWh=0 # full battery power in mWh

local batteries # batteries connected to the system
mapfile -t batteries < <(shopt -s nullglob; for f in /sys/class/power_supply/BAT*; do echo "$f"; done)
if [ -z "${batteries}" ]; then
return
fi
local accum_now_mWh=0 # current battery power in mWh
local accum_full_mWh=0 # full battery power in mWh
for battery in "${batteries[@]}"; do
if [ -f "${battery}"/energy_now ]; then
accum_now_mWh=$((accum_now_mWh + $(cat "${battery}"/energy_now)))
Expand All @@ -64,7 +67,6 @@ status_bat() {
accum_full_mWh=$((accum_full_mWh + full_mWh))
fi
done
local bat_pct=$((100*accum_now_mWh/accum_full_mWh))
local ac_present=false
Expand Down Expand Up @@ -110,7 +112,7 @@ status_disk() {
local pool=$(qvm-pool -i $(qubes-prefs default-pool))
size=$(echo "$pool" | grep 'size' | awk '{print $2}')
usage=$(echo "$pool" | grep 'usage' | awk '{print $2}')
free=$(($size - $usage))
free=$((size - usage))
case ${#free} in
1[3-5])
disk="$(($free / 1099511627776))T" ;;
Expand Down

0 comments on commit 87649d0

Please sign in to comment.