summaryrefslogtreecommitdiff
path: root/mac/.config/sketchybar.allapp/plugins/battery.sh
diff options
context:
space:
mode:
Diffstat (limited to 'mac/.config/sketchybar.allapp/plugins/battery.sh')
-rwxr-xr-xmac/.config/sketchybar.allapp/plugins/battery.sh42
1 files changed, 42 insertions, 0 deletions
diff --git a/mac/.config/sketchybar.allapp/plugins/battery.sh b/mac/.config/sketchybar.allapp/plugins/battery.sh
new file mode 100755
index 0000000..7487662
--- /dev/null
+++ b/mac/.config/sketchybar.allapp/plugins/battery.sh
@@ -0,0 +1,42 @@
+#!/bin/sh
+
+source "$CONFIG_DIR/colors.sh"
+
+PERCENTAGE="$(pmset -g batt | grep -Eo "\d+%" | cut -d% -f1)"
+CHARGING="$(pmset -g batt | grep 'AC Power')"
+
+if [ "$PERCENTAGE" = "" ]; then
+ exit 0
+fi
+
+case ${PERCENTAGE} in
+ [8-9][0-9] | 100)
+ ICON="􀛨"
+ ICON_COLOR=$BATTERY_1
+ ;;
+ 7[0-9])
+ ICON="􀺸"
+ ICON_COLOR=$BATTERY_2
+ ;;
+ [4-6][0-9])
+ ICON="􀺶"
+ ICON_COLOR=$BATTERY_3
+ ;;
+ [1-3][0-9])
+ ICON="􀛩"
+ ICON_COLOR=$BATTERY_4
+ ;;
+ [0-9])
+ ICON="􀛪"
+ ICON_COLOR=$BATTERY_5
+ ;;
+esac
+
+if [[ "$CHARGING" != "" ]]; then
+ ICON="􀢋"
+ ICON_COLOR=$YELLOW
+fi
+
+# The item invoking this script (name $NAME) will get its icon and label
+# updated with the current battery status
+sketchybar --set "$NAME" icon="$ICON" label="${PERCENTAGE}%" icon.color=${ICON_COLOR}