summaryrefslogtreecommitdiff
path: root/mac/.config/sketchybar.allapp/plugins/battery.sh
blob: 74876629abc445c8b62726a47121d876d16c6e1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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}