1
0
mirror of https://github.com/Foltik/dotfiles synced 2024-11-24 12:26:05 -05:00
dotfiles/cfg/i3blocks/laptop/blocks/battery

38 lines
1.1 KiB
Plaintext
Raw Normal View History

2017-07-26 14:00:04 -04:00
#!/bin/bash
BATTERY=$(echo "${BLOCK_INSTANCE}" | awk -F ';' '{print $1}')
OPT=$(echo "${BLOCK_INSTANCE}" | awk -F ';' '{print $2}')
BATTERY_INFO=$(acpi -b | grep "Battery ${BATTERY}")
BATTERY_STATE=$(echo "${BATTERY_INFO}" | grep -wo "Full\|Charging\|Discharging")
BATTERY_POWER=$(echo "${BATTERY_INFO}" | grep -o '[0-9]\+%' | tr -d '%')
BATTERY_REMAINING=$(acpi -b | grep remaining | awk '{print $5}')
URGENT_VALUE=10
if [[ "${BATTERY_STATE}" = "Charging" ]]; then
if [[ "${OPT}" = "rem" ]]; then
echo "${BATTERY_POWER}%+ ${BATTERY_REMAINING}"
echo "${BATTERY_POWER}%+ ${BATTERY_REMAINING}"
else
echo "${BATTERY_POWER}%+"
echo "${BATTERY_POWER}%+"
fi
echo ""
elif [[ "${BATTERY_STATE}" = "Discharging" ]]; then
if [[ "${OPT}" = "rem" ]]; then
echo "${BATTERY_POWER}%- ${BATTERY_REMAINING}"
echo "${BATTERY_POWER}%- ${BATTERY_REMAINING}"
else
echo "${BATTERY_POWER}%-"
echo "${BATTERY_POWER}%-"
fi
echo ""
else
echo "${BATTERY_POWER}%"
echo "${BATTERY_POWER}%"
echo ""
fi
if [[ "${BATTERY_POWER}" -le "${URGENT_VALUE}" ]]; then
exit 33
fi