Created
December 1, 2016 15:04
-
-
Save toanant/eaf7d566dd2ee850149f8df517d6a4ac to your computer and use it in GitHub Desktop.
Revisions
-
toanant created this gist
Dec 1, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ #!/bin/sh while true; do # Minimum battery level in percentage. # If remaning battery percentage is less than this then a notification will be shown. MINIMUM_LEVEL=23; # Determine battery status BATTERY_STATUS=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep -E "state" | sed -E 's/state://' | sed 's/^[ \t]*//;s/[ \t]*$//'); # Calculate remaining battery REMAING_BATTERY=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep -E "percentage"|sed -r 's/([^0-9]*([0-9]*)){1}.*/\2/'); if [ "$BATTERY_STATUS" = "discharging" ] then if [ $REMAING_BATTERY -lt $MINIMUM_LEVEL ] then # Send a notification notify-send -u critical 'Low Battery' $REMAING_BATTERY' % battery is remaining. Please plug your charger.'; fi fi # Sleep for 45 seconds and then recheck sleep 45; done;