Refactor battery, handle when not a laptop so no battery
This commit is contained in:
parent
a5f6b8fb3e
commit
aaba650078
1 changed files with 15 additions and 11 deletions
|
@ -1,16 +1,20 @@
|
|||
#!/bin/bash
|
||||
|
||||
icon=""
|
||||
percent="$(upower -d | grep 'percentage' | awk '{print $2}' | head -n 1)"
|
||||
remaining="$(upower -d | grep 'time to empty' | awk -F: '{print $2}' | awk '{print $1,$2}' | head -n 1)"
|
||||
battery="$(upower -d | awk '/on-battery/ {print $2}')"
|
||||
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 [ -n "$remaining" ] && [ "$(echo "$percent" | awk -F% '{print $1}')" -lt "$THRESHOLD" ]; then
|
||||
notify-send "CHARGE BATTERY"
|
||||
for file in /dev/pts/*; do
|
||||
if [ "$(ls -l "$file" | awk '{print $5}')" = '136,' ]; then
|
||||
echo "CHARGE BATTERY" >> "$file"
|
||||
fi
|
||||
done
|
||||
if [ "$battery" = 'yes' ]; then
|
||||
if [ -n "$remaining" ] && [ "$(echo "$percent" | awk -F% '{print $1}')" -lt "$THRESHOLD" ]; then
|
||||
notify-send "CHARGE BATTERY"
|
||||
for file in /dev/pts/*; do
|
||||
if [ "$(ls -l "$file" | awk '{print $5}')" = '136,' ]; then
|
||||
echo "CHARGE BATTERY" >> "$file"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
echo "${icon} ${percent} (${remaining})"
|
||||
else
|
||||
echo ""
|
||||
fi
|
||||
|
||||
echo "${icon} ${percent} (${remaining})"
|
||||
|
|
Loading…
Add table
Reference in a new issue