scripts

Various scripts for UNIX-like systems
git clone https://git.tronto.net/scripts
Download | Log | Files | Refs | README

battery-checknow (623B)


      1 #!/bin/sh
      2 
      3 # Check battery state, save result to a file. Pop up notification if changed.
      4 # Requires: battery-status, notify-battery
      5 
      6 file="${XDG_DATA_HOME:-$HOME/.local/share}/batterystatus"
      7 notify="notify push"
      8 low=20
      9 crit=15
     10 
     11 new=$(battery-status)
     12 level=$(echo "$new" | sed 's/%.*//')
     13 status=$(echo "$new" | awk '{print $2}')
     14 
     15 [ "$status" = "Discharging" ] && [ "$level" -le "$low" ]  && status="Low"
     16 [ "$status" = "Discharging" ] && [ "$level" -le "$crit" ] && status="Critical"
     17 
     18 if [ "$status" != "$(cat "$file")" ] || [ "$status" = "Critical" ]; then
     19 	$notify "Battery: $(battery-status)"
     20 fi
     21 
     22 echo "$status" > "$file"