Refactor battery, handle when not a laptop so no battery

This commit is contained in:
flyingscorpio@clevo 2022-02-16 19:47:55 +01:00
parent a5f6b8fb3e
commit aaba650078

View file

@ -1,9 +1,11 @@
#!/bin/bash #!/bin/bash
icon="" icon=""
percent="$(upower -d | grep 'percentage' | awk '{print $2}' | head -n 1)" battery="$(upower -d | awk '/on-battery/ {print $2}')"
remaining="$(upower -d | grep 'time to empty' | awk -F: '{print $2}' | awk '{print $1,$2}' | head -n 1)" percent="$(upower -d | awk '/percentage/ {print $2}' | head -n 1)"
remaining="$(upower -d | awk -F: '/time to empty/ {print $2}' | awk '{print $1,$2}' | head -n 1)"
if [ "$battery" = 'yes' ]; then
if [ -n "$remaining" ] && [ "$(echo "$percent" | awk -F% '{print $1}')" -lt "$THRESHOLD" ]; then if [ -n "$remaining" ] && [ "$(echo "$percent" | awk -F% '{print $1}')" -lt "$THRESHOLD" ]; then
notify-send "CHARGE BATTERY" notify-send "CHARGE BATTERY"
for file in /dev/pts/*; do for file in /dev/pts/*; do
@ -12,5 +14,7 @@ if [ -n "$remaining" ] && [ "$(echo "$percent" | awk -F% '{print $1}')" -lt "$TH
fi fi
done done
fi fi
echo "${icon} ${percent} (${remaining})" echo "${icon} ${percent} (${remaining})"
else
echo ""
fi