mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2025-12-26 02:12:33 +01:00
adde battery and archlinux plugin
This commit is contained in:
parent
2e9492969b
commit
45e7a2fce4
3 changed files with 152 additions and 0 deletions
59
plugins/battery/battery.plugin.zsh
Normal file
59
plugins/battery/battery.plugin.zsh
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
#!/bin/sh
|
||||
|
||||
##defining path of battery
|
||||
if [ -e /proc/acpi/battery/BAT0/ ]
|
||||
then
|
||||
battpath="/proc/acpi/battery/BAT0"
|
||||
elif [ -e /proc/acpi/battery/BAT1/ ]
|
||||
then
|
||||
battpath="/proc/acpi/battery/BAT1"
|
||||
else
|
||||
echo "No battery found. Make sure that you have acpi support in your kernel"
|
||||
echo "and that the computer actually is a laptop :)"
|
||||
exit 1
|
||||
fi
|
||||
batt_prompt_perc(){
|
||||
fullcap=`grep "^last full capacity" $battpath/info | awk '{ print $4 }'`
|
||||
remcap=`grep "^remaining capacity" $battpath/state | awk '{ print $3 }'`
|
||||
|
||||
charge=$(( $remcap * 100 / $fullcap ))
|
||||
|
||||
# prevent a charge of more than 100% displaying
|
||||
if [ "$charge" -gt "99" ]
|
||||
then
|
||||
charge=100
|
||||
fi
|
||||
|
||||
color="red"
|
||||
if [ $charge -gt "80" ]
|
||||
then
|
||||
color="cyan"
|
||||
elif [ $charge -gt 60 ]
|
||||
then
|
||||
color="green"
|
||||
elif [ $charge -gt 25 ]
|
||||
then
|
||||
color="yellow"
|
||||
fi
|
||||
|
||||
echo -e "%F{$color}$charge%f"
|
||||
}
|
||||
|
||||
bat_prompt_acstt(){
|
||||
batstate=`grep "^charging state" $battpath/state | awk '{ print $3 }'`
|
||||
case "${batstate}" in
|
||||
'charged')
|
||||
clr="green"
|
||||
btst="°"
|
||||
;;
|
||||
'charging')
|
||||
clr="blue"
|
||||
btst="+"
|
||||
;;
|
||||
'discharging')
|
||||
clr="yellow"
|
||||
btst="-"
|
||||
;;
|
||||
esac
|
||||
echo -e "%F{$clr}$btst%f"
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue