mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2025-12-26 02:12:33 +01:00
change: make battery indicator change color based on status
This commit is contained in:
parent
1189065aed
commit
485439dddb
1 changed files with 13 additions and 2 deletions
|
|
@ -1,9 +1,20 @@
|
||||||
if [[ $(acpi | grep -c ^Battery) -gt 0 ]] ; then
|
if [[ $(acpi | grep -c '^Battery.*Discharging') -gt 0 ]] ; then
|
||||||
function battery_pct_remaining() { echo "$(acpi | cut -f2 -d ',' | tr -cd '[:digit:]')" }
|
function battery_pct_remaining() { echo "$(acpi | cut -f2 -d ',' | tr -cd '[:digit:]')" }
|
||||||
function battery_time_remaining() { echo $(acpi | cut -f3 -d ',') }
|
function battery_time_remaining() { echo $(acpi | cut -f3 -d ',') }
|
||||||
function battery_pct_prompt() { echo "%{$fg[red]%}[$(battery_pct_remaining)]%{$reset_color%}" }
|
function battery_pct_prompt() {
|
||||||
|
b=$(battery_pct_remaining)
|
||||||
|
if [ $b -gt 50 ] ; then
|
||||||
|
color='green'
|
||||||
|
elif [ $b -gt 20 ] ; then
|
||||||
|
color='yellow'
|
||||||
|
else
|
||||||
|
color='red'
|
||||||
|
fi
|
||||||
|
echo "%{$fg[$color]%}[$(battery_pct_remaining)%%]%{$reset_color%}"
|
||||||
|
}
|
||||||
else
|
else
|
||||||
error_msg='no battery'
|
error_msg='no battery'
|
||||||
function battery_pct_remaining() { echo $error_msg }
|
function battery_pct_remaining() { echo $error_msg }
|
||||||
function battery_time_remaining() { echo $error_msg }
|
function battery_time_remaining() { echo $error_msg }
|
||||||
|
function battery_pct_prompt() { echo '' }
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue