]>
git.rmz.io Git - dotfiles.git/blob - zsh/plugins/battery/battery.plugin.zsh
1 ###########################################
2 # Battery plugin for oh-my-zsh #
3 # Original Author: Peter hoeg (peterhoeg) #
4 # Email: peter@speartail.com #
5 ###########################################
6 # Author: Sean Jones (neuralsandwich) #
7 # Email: neuralsandwich@gmail.com #
8 # Modified to add support for Apple Mac #
9 ###########################################
11 if [[ $(uname) == "Darwin" ]] ; then
13 function battery_pct_remaining
() {
14 if [[ $(ioreg -rc AppleSmartBattery | grep -c '^.*"ExternalConnected"\ =\ No') -eq 1 ]] ; then
15 typeset
-F maxcapacity
=$(ioreg -rc "AppleSmartBattery"| grep '^.*"MaxCapacity"\ =\ ' | sed -e 's/^.*"MaxCapacity"\ =\ //')
16 typeset
-F currentcapacity
=$(ioreg -rc "AppleSmartBattery"| grep '^.*"CurrentCapacity"\ =\ ' | sed -e 's/^.*CurrentCapacity"\ =\ //')
17 integer i
=$(((currentcapacity/maxcapacity) * 100))
24 function battery_time_remaining
() {
25 if [[ $(ioreg -rc AppleSmartBattery | grep -c '^.*"ExternalConnected"\ =\ No') -eq 1 ]] ; then
26 timeremaining
=$(ioreg -rc "AppleSmartBattery"| grep '^.*"AvgTimeToEmpty"\ =\ ' | sed -e 's/^.*"AvgTimeToEmpty"\ =\ //')
27 echo "~$((timeremaining / 60)):$((timeremaining % 60))"
33 function battery_pct_prompt
() {
34 if [[ $(ioreg -rc AppleSmartBattery | grep -c '^.*"ExternalConnected"\ =\ No') -eq 1 ]] ; then
35 b
=$(battery_pct_remaining)
36 if [ $b -gt 50 ] ; then
38 elif [ $b -gt 20 ] ; then
43 echo "%{$fg[$color]%}[$(battery_pct_remaining)%%]%{$reset_color%}"
49 elif [[ $(uname) == "Linux" ]] ; then
51 if [[ $(acpi 2&>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] ; then
52 function battery_pct_remaining
() { echo "$(acpi | cut -f2 -d ',' | tr -cd '[:digit:]')" }
53 function battery_time_remaining
() { echo $(acpi | cut -f3 -d ',') }
54 function battery_pct_prompt
() {
55 b
=$(battery_pct_remaining)
56 if [ $b -gt 50 ] ; then
58 elif [ $b -gt 20 ] ; then
63 echo "%{$fg[$color]%}[$(battery_pct_remaining)%%]%{$reset_color%}"
66 error_msg
='no battery'
67 function battery_pct_remaining
() { echo $error_msg }
68 function battery_time_remaining
() { echo $error_msg }
69 function battery_pct_prompt
() { echo '' }