diff options
author | Dominik Ritter <dritter03@googlemail.com> | 2018-07-16 21:48:27 +0300 |
---|---|---|
committer | Dominik Ritter <dritter03@googlemail.com> | 2018-07-16 21:48:27 +0300 |
commit | 802af322ff3c0541cb89dac30362e576ff1f81a2 (patch) | |
tree | c5d29491b21e82771336e5d270c3f8b2a7350e55 /powerlevel9k.zsh-theme | |
parent | 74a3d2d6e2b88e9d4c89995373e0d176b47450d7 (diff) |
Add tests for battery segment
Additionally
- Add a fourth parameter to prompt_battery for better testability. This
parameter is the root prefix, so we can use our own test batteries.
Diffstat (limited to 'powerlevel9k.zsh-theme')
-rwxr-xr-x | powerlevel9k.zsh-theme | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index c1ea754f..eefcedde 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -409,12 +409,13 @@ prompt_battery() { 'charged' 'green' 'disconnected' "$DEFAULT_COLOR_INVERTED" ) + local ROOT_PREFIX="${4}" # Set default values if the user did not configure them set_default POWERLEVEL9K_BATTERY_LOW_THRESHOLD 10 - if [[ $OS =~ OSX && -f /usr/bin/pmset && -x /usr/bin/pmset ]]; then + if [[ $OS =~ OSX && -f "${ROOT_PREFIX}"/usr/bin/pmset && -x "${ROOT_PREFIX}"/usr/bin/pmset ]]; then # obtain battery information from system - local raw_data="$(pmset -g batt | awk 'FNR==2{print}')" + local raw_data="$(${ROOT_PREFIX}/usr/bin/pmset -g batt | awk 'FNR==2{print}')" # return if there is no battery on system [[ -z $(echo $raw_data | grep "InternalBattery") ]] && return @@ -446,7 +447,7 @@ prompt_battery() { fi if [[ "$OS" == 'Linux' ]] || [[ "$OS" == 'Android' ]]; then - local sysp="/sys/class/power_supply" + local sysp="${ROOT_PREFIX}/sys/class/power_supply" # Reported BAT0 or BAT1 depending on kernel version [[ -a $sysp/BAT0 ]] && local bat=$sysp/BAT0 @@ -468,8 +469,8 @@ prompt_battery() { [[ $bat_percent =~ 100 ]] && current_state="charged" [[ $bat_percent -lt 100 ]] && current_state="charging" fi - if [[ -f /usr/bin/acpi ]]; then - local time_remaining=$(acpi | awk '{ print $5 }') + if [[ -f ${ROOT_PREFIX}/usr/bin/acpi ]]; then + local time_remaining=$(${ROOT_PREFIX}/usr/bin/acpi | awk '{ print $5 }') if [[ $time_remaining =~ rate ]]; then local tstring="..." elif [[ $time_remaining =~ "[[:digit:]]+" ]]; then |