From a9c5670c2cf0e67324cbd83a37f73da772f6aecf Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Tue, 12 Apr 2016 09:54:03 +0200 Subject: [PATCH 1/2] Added AC indicator support on OS X Not sure about the logic for returning 1/0 from the function, though - will have to clarify. --- plugins/available/battery.plugin.bash | 24 ++++++++++++------- .../powerline-multiline.theme.bash | 2 +- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/plugins/available/battery.plugin.bash b/plugins/available/battery.plugin.bash index 85af5097..9646b0e7 100644 --- a/plugins/available/battery.plugin.bash +++ b/plugins/available/battery.plugin.bash @@ -2,15 +2,23 @@ cite about-plugin 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 + if command_exists acpi; + then + acpi -a | grep "on-line" + if [[ "$?" -eq 0 ]]; then + return 1 + else + return 0 fi + 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 + fi } battery_percentage(){ diff --git a/themes/powerline-multiline/powerline-multiline.theme.bash b/themes/powerline-multiline/powerline-multiline.theme.bash index 27d51d52..68f7858c 100644 --- a/themes/powerline-multiline/powerline-multiline.theme.bash +++ b/themes/powerline-multiline/powerline-multiline.theme.bash @@ -153,7 +153,7 @@ function __powerline_battery_prompt { else color="${BATTERY_STATUS_THEME_PROMPT_GOOD_COLOR}" fi - [[ "$(ac_adapter_connected)" ]] && battery_status="${BATTERY_AC_CHAR}${battery_status}" + ac_adapter_connected && battery_status="${BATTERY_AC_CHAR} ${battery_status}" echo "${battery_status}%|${color}" fi } From e5d50f0d979ada3b274a9c695170363cc81ace09 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Thu, 14 Apr 2016 08:16:32 +0200 Subject: [PATCH 2/2] 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. --- plugins/available/battery.plugin.bash | 16 ++++------------ .../powerline-multiline.theme.bash | 4 ++-- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/plugins/available/battery.plugin.bash b/plugins/available/battery.plugin.bash index 9646b0e7..80ff5bdb 100644 --- a/plugins/available/battery.plugin.bash +++ b/plugins/available/battery.plugin.bash @@ -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 } diff --git a/themes/powerline-multiline/powerline-multiline.theme.bash b/themes/powerline-multiline/powerline-multiline.theme.bash index 68f7858c..c4833756 100644 --- a/themes/powerline-multiline/powerline-multiline.theme.bash +++ b/themes/powerline-multiline/powerline-multiline.theme.bash @@ -35,7 +35,7 @@ LAST_STATUS_THEME_PROMPT_COLOR=196 CLOCK_THEME_PROMPT_COLOR=240 -BATTERY_AC_CHAR="⚡" +BATTERY_AC_CHAR=${BATTERY_AC_CHAR:="⚡"} BATTERY_STATUS_THEME_PROMPT_GOOD_COLOR=70 BATTERY_STATUS_THEME_PROMPT_LOW_COLOR=208 BATTERY_STATUS_THEME_PROMPT_CRITICAL_COLOR=160 @@ -153,7 +153,7 @@ function __powerline_battery_prompt { else color="${BATTERY_STATUS_THEME_PROMPT_GOOD_COLOR}" fi - ac_adapter_connected && battery_status="${BATTERY_AC_CHAR} ${battery_status}" + ac_adapter_connected && battery_status="${BATTERY_AC_CHAR}${battery_status}" echo "${battery_status}%|${color}" fi }