URI:
       juice - scripts - various script and utils
  HTML git clone git://z3bra.org/scripts
   DIR Log
   DIR Files
   DIR Refs
       ---
       juice (654B)
       ---
            1 #!/bin/sh
            2 
            3 # for notify-send
            4 export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus
            5 
            6 fmt='%d%%\n'
            7 treshold=10
            8 bat=/sys/class/power_supply/BAT0
            9 
           10 usage() {
           11         echo "usage: $(basename $0) [-hcnst]" >&2
           12 }
           13 
           14 c=$(cat $bat/capacity)
           15 s=$(cat $bat/status)
           16 v=$c
           17 
           18 while getopts "hcstn" OPT; do
           19         case $OPT in
           20         c) fmt='%d\n'; v=$c ;; # capacity
           21         s) fmt='%s\n'; v=$s ;; # charging status
           22         t) test "$s" = "Charging" -o "$c" -lt "$treshold"; exit $? ;;
           23         n) [ "$s" != "Charging" -a "$c" -lt "$treshold" ] \
           24                 && notify-send -u critical "🪫 low battery ($c%)"
           25                 exit ;;
           26         h) usage; exit 0 ;;
           27         *) usage; exit 1 ;;
           28         esac
           29 done
           30 shift $((OPTIND-1))
           31 
           32 printf "$fmt" "$v"