setup-cockpit/roles/i3/files/battery

41 lines
1.3 KiB
Bash
Executable file

#!/bin/bash
icon="${LABEL_100}"
percent="$(upower -d | awk '/percentage/ {print $2}' | head -n 1 | cut -d% -f1)"
remaining="$(upower -d | awk -F: '/time to empty/ {print $2}' | awk '{print $1,$2}' | head -n 1)"
if upower -d | grep '\bcharging\b' >/dev/null 2>&1; then
icon="${LABEL_CHARGING}"
echo "${icon} ${percent}%"
elif upower -d | grep '\bdischarging\b' >/dev/null 2>&1; then
if [ "$percent" -lt 10 ]; then
icon="${LABEL_10}"
elif [ "$percent" -lt 20 ]; then
icon="${LABEL_20}"
elif [ "$percent" -lt 30 ]; then
icon="${LABEL_30}"
elif [ "$percent" -lt 40 ]; then
icon="${LABEL_40}"
elif [ "$percent" -lt 50 ]; then
icon="${LABEL_50}"
elif [ "$percent" -lt 70 ]; then
icon="${LABEL_70}"
elif [ "$percent" -lt 80 ]; then
icon="${LABEL_80}"
elif [ "$percent" -lt 90 ]; then
icon="${LABEL_90}"
fi
if [ "$percent" -lt "$THRESHOLD" ]; then
icon="${LABEL_ALERT}"
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 "${icon}"
fi