Skip to content

Commit

Permalink
ewwbar: initialize eww-bat script variables
Browse files Browse the repository at this point in the history
If BATTERY_PATH-does not exist, variables are initialized with *empty*-value.
Empty/null value will generate following errors into logs:

ghaf-host ewwbar-ctrl[xx]: /nix/store/hash-eww-bat/bin/eww-bat: line 12: [: : integer expression expected
ghaf-host ewwbar-ctrl[xx]: (standard_in) 1: syntax error
ghaf-host ewwbar-ctrl[xx]: /nix/store/hash-eww-bat/bin/eww-bat: line 29: [: : integer expression expected

Signed-off-by: Tanel Dettenborn <[email protected]>
  • Loading branch information
Tanel Dettenborn authored and brianmcgillion committed Feb 12, 2025
1 parent 723ee0f commit e08d94a
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions modules/desktop/graphics/ewwbar/config/scripts/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ let
text = ''
get() {
BATTERY_PATH="/sys/class/power_supply/BAT0"
ENERGY_NOW=$(cat "$BATTERY_PATH/energy_now")
POWER_NOW=$(cat "$BATTERY_PATH/power_now")
CAPACITY=$(cat "$BATTERY_PATH/capacity")
STATUS=$(cat "$BATTERY_PATH/status")
if [ "$POWER_NOW" -eq 0 ]; then
ENERGY_NOW=$([ -d "$BATTERY_PATH" ] && cat "$BATTERY_PATH/energy_now" || echo 0)
POWER_NOW=$([ -d "$BATTERY_PATH" ] && cat "$BATTERY_PATH/power_now" || echo 0)
CAPACITY=$([ -d "$BATTERY_PATH" ] && cat "$BATTERY_PATH/capacity" || echo 0)
STATUS=$([ -d "$BATTERY_PATH" ] && cat "$BATTERY_PATH/status" || echo 0)
if (( POWER_NOW == 0 )); then
echo "{
\"hours\": \"0\",
\"minutes_total\": \"0\",
Expand All @@ -45,7 +45,7 @@ let
MINUTES_REMAINDER=$(echo "($TIME_REMAINING - $HOURS) * 60" | bc | awk '{printf "%d\n", $1}')
# If both hours and minutes are 0, return 0 for both
if [ "$HOURS" -eq 0 ] && [ "$MINUTES" -eq 0 ]; then
if (( HOURS == 0 && MINUTES == 0 )); then
HOURS=0
MINUTES=0
fi
Expand Down

0 comments on commit e08d94a

Please sign in to comment.