Indicate if the battery is (dis)charging
Displays: * a green ⌁ if the battery is charging and above a given threshold, * a yellow ⌁ if the battery is charging and under threshold, * a red ⌁ if the battery is discharging but above threshold;
This commit is contained in:
parent
697bb3a31a
commit
508b218004
@ -30,8 +30,11 @@ A liquid prompt displaying everything may look like this:
|
|||||||
|
|
||||||
It displays:
|
It displays:
|
||||||
|
|
||||||
* the average of the batteries remaining power, if it is under a given
|
* a green ⌁ if the battery is charging and above a given threshold,
|
||||||
threshold, with a colormap too;
|
a yellow ⌁ if the battery is charging and under threshold,
|
||||||
|
a red ⌁ if the battery is discharging but above threshold;
|
||||||
|
* the average of the batteries remaining power, if it is under the given
|
||||||
|
threshold, with a colormap, going more and more red with decreasing power;
|
||||||
* the average of the processors load, if it is over a given limit, with a
|
* the average of the processors load, if it is over a given limit, with a
|
||||||
colormap that became more and more noticeable with increasing load;
|
colormap that became more and more noticeable with increasing load;
|
||||||
* the number of detached sessions (`screen`), if there is any;
|
* the number of detached sessions (`screen`), if there is any;
|
||||||
|
86
liquidprompt
86
liquidprompt
@ -618,37 +618,87 @@ __svn_branch_color()
|
|||||||
##################
|
##################
|
||||||
|
|
||||||
# Get the battery status in percent
|
# Get the battery status in percent
|
||||||
# returns 1 if no battery support
|
# returns 0 (and battery level) if battery is discharging and under threshold
|
||||||
|
# returns 1 (and battery level) if battery is discharging and above threshold
|
||||||
|
# returns 2 (and battery level) if battery is charging but under threshold
|
||||||
|
# returns 3 (and battery level) if battery is charging and above threshold
|
||||||
|
# returns 4 if no battery support
|
||||||
__battery()
|
__battery()
|
||||||
{
|
{
|
||||||
command -v acpi >/dev/null 2>&1 || return 1;
|
command -v acpi >/dev/null 2>&1 || return 4; # or no battery support
|
||||||
bat=$(acpi --battery 2>/dev/null | sed "s/^Battery .*, \([0-9]*\)%.*$/\1/")
|
local acpi=$(acpi --battery 2>/dev/null)
|
||||||
if [[ "${bat}" == "" ]] ; then
|
local bat=$( echo $acpi | sed "s/^Battery .*, \([0-9]*\)%.*$/\1/")
|
||||||
return 1
|
|
||||||
fi
|
if [[ -z "${bat}" ]] ; then
|
||||||
if [[ ${bat} -le $LP_BATTERY_THRESHOLD ]] ; then
|
# not battery level found
|
||||||
echo -n "${bat}"
|
return 4
|
||||||
return 0
|
|
||||||
|
# discharging
|
||||||
|
elif [[ "$acpi" == *"Discharging"* ]] ; then
|
||||||
|
if [[ ${bat} -le $LP_BATTERY_THRESHOLD ]] ; then
|
||||||
|
# under threshold
|
||||||
|
echo -n "${bat}"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
# above threshold
|
||||||
|
echo -n "${bat}"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# charging
|
||||||
else
|
else
|
||||||
return 1
|
if [[ ${bat} -le $LP_BATTERY_THRESHOLD ]] ; then
|
||||||
|
# under threshold
|
||||||
|
echo -n "${bat}"
|
||||||
|
return 2
|
||||||
|
else
|
||||||
|
# above threshold
|
||||||
|
echo -n "${bat}"
|
||||||
|
return 3
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Compute a gradient of background/foreground colors depending on the battery status
|
# Compute a gradient of background/foreground colors depending on the battery status
|
||||||
|
# Display:
|
||||||
|
# a green ⌁ if the battery is charging and above threshold
|
||||||
|
# a yellow ⌁ if the battery is charging and under threshold
|
||||||
|
# a red ⌁ if the battery is discharging but above threshold
|
||||||
__battery_color()
|
__battery_color()
|
||||||
{
|
{
|
||||||
|
local mark="⌁"
|
||||||
|
local bat
|
||||||
|
local ret
|
||||||
bat=$(__battery)
|
bat=$(__battery)
|
||||||
if [[ "$?" = "1" ]] ; then return; fi; # no battery support
|
ret=$?
|
||||||
|
|
||||||
if [[ "$bat" != "" ]] ; then
|
if [[ $ret == 4 || $bat == 100 ]] ; then
|
||||||
if [[ ${bat} -gt $LP_BATTERY_THRESHOLD ]] ; then
|
# no battery support or battery full: nothing displayed
|
||||||
return; # nothing displayed above 75%
|
return
|
||||||
fi
|
elif [[ $ret == 3 && $bat != 100 ]] ; then
|
||||||
|
# charging and above threshold and not 100%
|
||||||
|
# green ⌁
|
||||||
|
echo -ne "${GREEN}$mark${NO_COL}"
|
||||||
|
return
|
||||||
|
elif [[ $ret == 2 ]] ; then
|
||||||
|
# charging but under threshold
|
||||||
|
# yellow ⌁
|
||||||
|
echo -ne "${YELLOW}$mark${NO_COL}"
|
||||||
|
return
|
||||||
|
elif [[ $ret == 1 ]] ; then
|
||||||
|
# discharging but above threshold
|
||||||
|
# red ⌁
|
||||||
|
echo -ne "${RED}$mark${NO_COL}"
|
||||||
|
return
|
||||||
|
|
||||||
ret="⌁${NO_COL}"
|
# discharging and under threshold
|
||||||
if [[ ${bat} -le 75 ]] && [[ ${bat} -gt 50 ]] ; then
|
elif [[ "$bat" != "" ]] ; then
|
||||||
|
ret="${mark}${NO_COL}"
|
||||||
|
if [[ ${bat} -le 100 ]] && [[ ${bat} -gt 75 ]] ; then
|
||||||
|
ret="${ret}${GREEN}"
|
||||||
|
elif [[ ${bat} -le 75 ]] && [[ ${bat} -gt 50 ]] ; then
|
||||||
ret="${ret}${BOLD_GREEN}"
|
ret="${ret}${BOLD_GREEN}"
|
||||||
elif [[ ${bat} -le 40 ]] && [[ ${bat} -gt 20 ]] ; then
|
elif [[ ${bat} -le 50 ]] && [[ ${bat} -gt 20 ]] ; then
|
||||||
ret="${ret}${BOLD_YELLOW}"
|
ret="${ret}${BOLD_YELLOW}"
|
||||||
elif [[ ${bat} -le 20 ]] && [[ ${bat} -gt 10 ]] ; then
|
elif [[ ${bat} -le 20 ]] && [[ ${bat} -gt 10 ]] ; then
|
||||||
ret="${ret}${BOLD_RED}"
|
ret="${ret}${BOLD_RED}"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user