suppressed error on linux from battery plugin, added fully-charged implementation on OSX

This commit is contained in:
Nikhil Gupta 2014-10-12 18:44:08 +05:30
commit c02444d81e

View file

@ -22,6 +22,10 @@ if [[ "$OSTYPE" = darwin* ]] ; then
[ $(ioreg -rc AppleSmartBattery | grep -c '^.*"ExternalConnected"\ =\ Yes') -eq 1 ] [ $(ioreg -rc AppleSmartBattery | grep -c '^.*"ExternalConnected"\ =\ Yes') -eq 1 ]
} }
function fully_charged() {
[[ $(ioreg -rc "AppleSmartBattery"| grep '^.*"FullyCharged"\ =\ ' | sed -e 's/^.*"FullyCharged"\ =\ //') == "Yes" ]]
}
function battery_pct_remaining() { function battery_pct_remaining() {
if plugged_in ; then if plugged_in ; then
echo "External Power" echo "External Power"
@ -70,9 +74,16 @@ elif [[ $(uname) == "Linux" ]] ; then
! [[ $(acpi 2&>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] ! [[ $(acpi 2&>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]]
} }
function plugged_in() {
battery_is_charging
}
function fully_charged() {
}
function battery_pct() { function battery_pct() {
if (( $+commands[acpi] )) ; then if (( $+commands[acpi] )) ; then
echo "$(acpi | cut -f2 -d ',' | tr -cd '[:digit:]')" echo "$(acpi 2&>/dev/null | cut -f2 -d ',' | tr -cd '[:digit:]')"
fi fi
} }
@ -91,7 +102,7 @@ elif [[ $(uname) == "Linux" ]] ; then
} }
function battery_pct_prompt() { function battery_pct_prompt() {
b=$(battery_pct_remaining) b=$(battery_pct_remaining)
if [[ $(acpi 2&>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] ; then if [[ $(acpi 2&>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] ; then
if [ $b -gt 50 ] ; then if [ $b -gt 50 ] ; then
color='green' color='green'
@ -107,7 +118,17 @@ elif [[ $(uname) == "Linux" ]] ; then
} }
else else
# Empty functions so we don't cause errors in prompts # Empty functions so we don't cause errors in prompts
function plugged_in() {
}
function fully_charged() {
}
function battery_is_charging() {
}
function battery_pct_remaining() { function battery_pct_remaining() {
} }