Now supports multiple batteries
Now indicates status (^ Charging, v Discharging, = Full or Unknown)
Now supports different functions for different OSes
TODO: add configurability (zstyle, etc.)
TODO: add support for other OSes (ATM, only Linux is supported)
# - debian_chroot
# - vcs_info setup and version specific fixes
# - debian_chroot
# - vcs_info setup and version specific fixes
-# display battery status on right side of prompt via running 'BATTERY=1 zsh'
+# display battery status on right side of prompt using 'BATTERY=1' in .zshrc.pre
if [[ $BATTERY -gt 0 ]] ; then
if [[ $BATTERY -gt 0 ]] ; then
- if ! check_com -c acpi ; then
+ if ! islinux ; then
+ # not yet supported
BATTERY=0
fi
fi
battery() {
if [[ $BATTERY -gt 0 ]] ; then
BATTERY=0
fi
fi
battery() {
if [[ $BATTERY -gt 0 ]] ; then
- PERCENT="${${"$(acpi 2>/dev/null)"}/(#b)[[:space:]]#Battery <->: [^0-9]##, (<->)%*/${match[1]}}"
- if [[ -z "$PERCENT" ]] ; then
- PERCENT='acpi not present'
- else
- if [[ "$PERCENT" -lt 20 ]] ; then
- PERCENT="warning: ${PERCENT}%%"
- else
- PERCENT="${PERCENT}%%"
- fi
+ if islinux ; then
+ batterylinux
+batterylinux(){
+PERCENT=''
+local batteries bat capacity
+batteries=( /sys/class/power_supply/BAT*(N) )
+if (( $#batteries > 0 )) ; then
+ for bat in $batteries ; do
+ capacity=$(< $bat/capacity)
+ case $(< $bat/status) in
+ Charging)
+ PERCENT+=" ^"
+ ;;
+ Discharging)
+ if (( capacity < 20 )) ; then
+ PERCENT+=" !v"
+ else
+ PERCENT+=" v"
+ fi
+ ;;
+ *) # Full, Unknown
+ PERCENT+=" ="
+ ;;
+ esac
+ PERCENT+="${capacity}%%"
+ done
+fi
+}
+
# set variable debian_chroot if running in a chroot with /etc/debian_chroot
if [[ -z "$debian_chroot" ]] && [[ -r /etc/debian_chroot ]] ; then
debian_chroot=$(</etc/debian_chroot)
# set variable debian_chroot if running in a chroot with /etc/debian_chroot
if [[ -z "$debian_chroot" ]] && [[ -r /etc/debian_chroot ]] ; then
debian_chroot=$(</etc/debian_chroot)