mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-01-02 02:19:06 +01:00
Merge 6428159e58 into d05b2010ff
This commit is contained in:
commit
a55ad9a71c
1 changed files with 17 additions and 10 deletions
|
|
@ -1,8 +1,18 @@
|
|||
if [[ $(acpi 2&>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] ; then
|
||||
function battery_pct_remaining() { echo "$(acpi | cut -f2 -d ',' | tr -cd '[:digit:]')" }
|
||||
function battery_time_remaining() { echo $(acpi | cut -f3 -d ',') }
|
||||
function battery_pct_prompt() {
|
||||
b=$(battery_pct_remaining)
|
||||
elif [[ $(pmset -g ps 2&>/dev/null | grep -c -- '-InternalBattery-') -gt 0 ]] ; then
|
||||
function battery_pct_remaining() { echo "$(pmset -g ps | tr -cd '[:digit:][:blank:]:' | awk '{print $2}')" }
|
||||
function battery_time_remaining() { echo "$(pmset -g ps | tr -cd '[:digit:][:blank:]:' | awk '{print $3}')" }
|
||||
else
|
||||
error_msg='no battery'
|
||||
function battery_pct_remaining() { echo $error_msg }
|
||||
function battery_time_remaining() { echo $error_msg }
|
||||
fi
|
||||
|
||||
function battery_pct_prompt() {
|
||||
b=$(battery_pct_remaining)
|
||||
if [[ $b == <-> ]] ; then
|
||||
if [ $b -gt 50 ] ; then
|
||||
color='green'
|
||||
elif [ $b -gt 20 ] ; then
|
||||
|
|
@ -10,11 +20,8 @@ if [[ $(acpi 2&>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] ; then
|
|||
else
|
||||
color='red'
|
||||
fi
|
||||
echo "%{$fg[$color]%}[$(battery_pct_remaining)%%]%{$reset_color%}"
|
||||
}
|
||||
else
|
||||
error_msg='no battery'
|
||||
function battery_pct_remaining() { echo $error_msg }
|
||||
function battery_time_remaining() { echo $error_msg }
|
||||
function battery_pct_prompt() { echo '' }
|
||||
fi
|
||||
echo "%{$fg[$color]%}[$b%%]%{$reset_color%}"
|
||||
else
|
||||
echo ''
|
||||
fi
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue