summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorMarc Cornellà <marc.cornella@live.com>2020-02-11 13:49:04 +0100
committerMarc Cornellà <marc.cornella@live.com>2020-02-11 21:25:38 +0100
commit39e61614f206f6a552f53c8d1a8b956d8c9ab32f (patch)
tree6558ab3e6b51fa2b9ac5eb5cffe9ea331fdd77af /plugins
parent1bd7a7ad21c51268ba0f9a0d8b643a82b5788a6a (diff)
downloadzsh-39e61614f206f6a552f53c8d1a8b956d8c9ab32f.tar.gz
zsh-39e61614f206f6a552f53c8d1a8b956d8c9ab32f.tar.bz2
zsh-39e61614f206f6a552f53c8d1a8b956d8c9ab32f.zip
Clean up Linux battery commands and syntax
Diffstat (limited to 'plugins')
-rw-r--r--plugins/battery/battery.plugin.zsh20
1 files changed, 10 insertions, 10 deletions
diff --git a/plugins/battery/battery.plugin.zsh b/plugins/battery/battery.plugin.zsh
index 5322dd18a..c1037ad26 100644
--- a/plugins/battery/battery.plugin.zsh
+++ b/plugins/battery/battery.plugin.zsh
@@ -116,17 +116,17 @@ elif [[ "$OSTYPE" = freebsd* ]] ; then
elif [[ "$OSTYPE" = linux* ]] ; then
function battery_is_charging() {
- ! [[ $(acpi 2>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]]
+ ! acpi 2>/dev/null | command grep -q '^Battery.*Discharging'
}
function battery_pct() {
if (( $+commands[acpi] )) ; then
- echo "$(acpi 2>/dev/null | cut -f2 -d ',' | tr -cd '[:digit:]')"
+ acpi 2>/dev/null | cut -f2 -d ',' | tr -cd '[:digit:]'
fi
}
function battery_pct_remaining() {
- if [ ! $(battery_is_charging) ] ; then
+ if ! battery_is_charging; then
battery_pct
else
echo "External Power"
@@ -134,15 +134,17 @@ elif [[ "$OSTYPE" = linux* ]] ; then
}
function battery_time_remaining() {
- if [[ $(acpi 2>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] ; then
- echo $(acpi 2>/dev/null | cut -f3 -d ',')
+ if ! battery_is_charging; then
+ acpi 2>/dev/null | cut -f3 -d ','
fi
}
function battery_pct_prompt() {
- b=$(battery_pct_remaining)
- if [[ $(acpi 2>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] ; then
- if [ $b -gt 50 ] ; then
+ local b=$(battery_pct_remaining)
+ if battery_is_charging; then
+ echo "∞"
+ else
+ if [[ $b -gt 50 ]]; then
color='green'
elif [ $b -gt 20 ] ; then
color='yellow'
@@ -150,8 +152,6 @@ elif [[ "$OSTYPE" = linux* ]] ; then
color='red'
fi
echo "%{$fg[$color]%}$(battery_pct_remaining)%%%{$reset_color%}"
- else
- echo "∞"
fi
}