mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-02-13 03:01:32 +01:00
* Updated algorithms to determine time remaining
* added functions to detect if charging, and pull multi-use shell-outs into functions * added functions to determine time to complete charge
This commit is contained in:
parent
a38af27991
commit
f12e52aea3
1 changed files with 34 additions and 8 deletions
|
|
@ -17,25 +17,45 @@ if [[ $(uname) == "Darwin" ]] ; then
|
||||||
echo $i
|
echo $i
|
||||||
}
|
}
|
||||||
|
|
||||||
function battery_pct_remaining() {
|
function charger_connected() {
|
||||||
if [[ $(ioreg -rc AppleSmartBattery | grep -c '^.*"ExternalConnected"\ =\ No') -eq 1 ]] ; then
|
if [[ $(ioreg -rc AppleSmartBattery | grep -c '^.*"ExternalConnected"\ =\ No') -eq 1 ]] ; then
|
||||||
battery_pct
|
echo "NO"
|
||||||
else
|
else
|
||||||
echo "External Power"
|
echo "YES"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function charging_state() {
|
||||||
|
if [[ $(charger_connected) == "YES" ]] ; then
|
||||||
|
echo "C"
|
||||||
|
else
|
||||||
|
echo "D"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function battery_pct_remaining() {
|
||||||
|
echo "$(battery_pct)"
|
||||||
|
}
|
||||||
|
|
||||||
|
function time_to_full {
|
||||||
|
echo $(ioreg -rc "AppleSmartBattery"| grep '^.*"AvgTimeToFull"\ =\ ' | sed -e 's/^.*"AvgTimeToFull"\ =\ //')
|
||||||
|
}
|
||||||
|
function time_to_empty {
|
||||||
|
echo $(ioreg -rc "AppleSmartBattery"| grep '^.*"TimeRemaining"\ =\ ' | sed -e 's/^.*"TimeRemaining"\ =\ //')
|
||||||
|
}
|
||||||
|
|
||||||
function battery_time_remaining() {
|
function battery_time_remaining() {
|
||||||
if [[ $(ioreg -rc AppleSmartBattery | grep -c '^.*"ExternalConnected"\ =\ No') -eq 1 ]] ; then
|
timeremaining=$(time_to_empty)
|
||||||
timeremaining=$(ioreg -rc "AppleSmartBattery"| grep '^.*"AvgTimeToEmpty"\ =\ ' | sed -e 's/^.*"AvgTimeToEmpty"\ =\ //')
|
timetofull=$(time_to_full)
|
||||||
|
if [[ $(charger_connected) == "NO" ]] ; then
|
||||||
echo "~$((timeremaining / 60)):$((timeremaining % 60))"
|
echo "~$((timeremaining / 60)):$((timeremaining % 60))"
|
||||||
else
|
else
|
||||||
echo "∞"
|
echo "~$((timetofull / 60)):$((timetofull % 60))"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function battery_pct_prompt () {
|
function battery_pct_prompt () {
|
||||||
if [[ $(ioreg -rc AppleSmartBattery | grep -c '^.*"ExternalConnected"\ =\ No') -eq 1 ]] ; then
|
if [[ $(charger_connected) == "NO" ]] ; then
|
||||||
b=$(battery_pct_remaining)
|
b=$(battery_pct_remaining)
|
||||||
if [ $b -gt 50 ] ; then
|
if [ $b -gt 50 ] ; then
|
||||||
color='green'
|
color='green'
|
||||||
|
|
@ -50,6 +70,7 @@ if [[ $(uname) == "Darwin" ]] ; then
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
elif [[ $(uname) == "Linux" ]] ; then
|
elif [[ $(uname) == "Linux" ]] ; then
|
||||||
|
|
||||||
function battery_pct_remaining() {
|
function battery_pct_remaining() {
|
||||||
|
|
@ -89,4 +110,9 @@ else
|
||||||
|
|
||||||
function battery_pct_prompt() {
|
function battery_pct_prompt() {
|
||||||
}
|
}
|
||||||
|
function charger_connected() {
|
||||||
|
}
|
||||||
|
function charging_state() {
|
||||||
|
}
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue