1
0
mirror of https://github.com/Foltik/dotfiles synced 2024-11-28 05:27:06 -05:00
dotfiles/cfg/i3blocks/laptop/blocks/battery
2017-07-26 11:05:09 -07:00

38 lines
1.1 KiB
Bash
Executable File

#!/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