Simplified logic for both Linux and OS X

Avoiding the if statements, using exit code of `grep -q` instead.

Reverted the change that adds a space after the AC char. Opting for a
default value, allowing to override from one's profile.
This commit is contained in:
Nils Winkler
2016-04-14 08:16:32 +02:00
parent a9c5670c2c
commit e5d50f0d97
2 changed files with 6 additions and 14 deletions

View File

@@ -4,20 +4,12 @@ about-plugin 'display info about your battery charge level'
ac_adapter_connected(){
if command_exists acpi;
then
acpi -a | grep "on-line"
if [[ "$?" -eq 0 ]]; then
return 1
else
return 0
fi
acpi -a | grep -q "on-line"
return $?
elif command_exists ioreg;
then
local IOREG_OUTPUT=$(ioreg -n AppleSmartBattery -r | grep '"ExternalConnected"' | awk -F'=' '{print $2}')
if [[ "$IOREG_OUTPUT" == *"Yes"* ]]; then
return 0
else
return 1
fi
ioreg -n AppleSmartBattery -r | grep -q '"ExternalConnected" = Yes'
return $?
fi
}