From: Michael Prokop Date: Fri, 27 Jan 2017 14:18:23 +0000 (+0100) Subject: zshrc: support systems without capacity file in batterylinux() [Closes: issue1333] X-Git-Tag: v0.13.2~1 X-Git-Url: http://git.grml.org/?p=grml-etc-core.git;a=commitdiff_plain;h=875b6d6e7e951cb8a2497b1503fdc3f59399f8e1 zshrc: support systems without capacity file in batterylinux() [Closes: issue1333] Thanks: Axel Beckert for the patch --- diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index a7b70d2..0bf68f8 100644 --- a/etc/zsh/zshrc +++ b/etc/zsh/zshrc @@ -1761,7 +1761,13 @@ local batteries bat capacity batteries=( /sys/class/power_supply/BAT*(N) ) if (( $#batteries > 0 )) ; then for bat in $batteries ; do - capacity=$(< $bat/capacity) + if [[ -e $bat/capacity ]]; then + capacity=$(< $bat/capacity) + else + typeset -F energy_full=$(< $bat/energy_full) + typeset -F energy_now=$(< $bat/energy_now) + typeset -i capacity=$(( 100 * $energy_now / $energy_full)) + fi case $(< $bat/status) in Charging) GRML_BATTERY_LEVEL+=" ^"