Skip to content

Commit 215de6d

Browse files
SilverEzhikmartinbeentjes
authored andcommitted
Use battery percentage icons (#59)
* Add dynamic battery level icons * Update README to use correct battery icon variables
1 parent b630ec8 commit 215de6d

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ By default, these icons are displayed:
8080

8181
- charged: ":battery:" ("❇ " when not on OS X)
8282
- charging: ":zap:"
83-
- discharging: (nothing shown)
83+
- discharging: Moon icons depending on your battery level
8484
- attached but not charging: ":warning:"
8585

8686
You can change these defaults by adding the following to `.tmux.conf` (the
@@ -90,6 +90,10 @@ following lines are not in the code block so that emojis can be seen):
9090
- set -g @batt_charging_icon ":+1:"
9191
- set -g @batt_discharging_icon ":thumbsdown:"
9292
- set -g @batt_attached_icon ":neutral_face:"
93+
- set -g @batt_full_charge_icon "🌕 "
94+
- set -g @batt_high_charge_icon "🌖 "
95+
- set -g @batt_medium_charge_icon "🌗 "
96+
- set -g @batt_low_charge_icon "🌘 "
9397

9498
Don't forget to reload tmux environment (`$ tmux source-file ~/.tmux.conf`)
9599
after you do this.

scripts/battery_icon.sh

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,20 @@ source "$CURRENT_DIR/helpers.sh"
88
charged_icon=""
99
charging_icon=""
1010
attached_icon=""
11-
discharging_icon=""
11+
# discharging_icon=""
12+
full_charge_icon=""
13+
high_charge_icon=""
14+
medium_charge_icon=""
15+
low_charge_icon=""
1216

1317
charged_default=""
1418
charged_default_osx="🔋 "
1519
charging_default="⚡️ "
1620
attached_default="⚠️ "
17-
discharging_default=""
21+
full_charge_icon_default="🌕 "
22+
high_charge_icon_default="🌖 "
23+
medium_charge_icon_default="🌗 "
24+
low_charge_icon_default="🌘 "
1825

1926
charged_default() {
2027
if is_osx; then
@@ -29,7 +36,10 @@ get_icon_settings() {
2936
charged_icon=$(get_tmux_option "@batt_charged_icon" "$(charged_default)")
3037
charging_icon=$(get_tmux_option "@batt_charging_icon" "$charging_default")
3138
attached_icon=$(get_tmux_option "@batt_attached_icon" "$attached_default")
32-
discharging_icon=$(get_tmux_option "@batt_discharging_icon" "$discharging_default")
39+
full_charge_icon=$(get_tmux_option "@batt_full_charge_icon" "$full_charge_icon_default")
40+
high_charge_icon=$(get_tmux_option "@batt_high_charge_icon" "$high_charge_icon_default")
41+
medium_charge_icon=$(get_tmux_option "@batt_medium_charge_icon" "$medium_charge_icon_default")
42+
low_charge_icon=$(get_tmux_option "@batt_low_charge_icon" "$low_charge_icon_default")
3343
}
3444

3545
print_icon() {
@@ -39,7 +49,19 @@ print_icon() {
3949
elif [[ $status =~ (^charging) ]]; then
4050
printf "$charging_icon"
4151
elif [[ $status =~ (^discharging) ]]; then
42-
printf "$discharging_icon"
52+
# use code from the bg color
53+
percentage=$($CURRENT_DIR/battery_percentage.sh | sed -e 's/%//')
54+
if [ $percentage -eq 100 ]; then
55+
printf $full_charge_icon
56+
elif [ $percentage -le 99 -a $percentage -ge 51 ];then
57+
printf $high_charge_icon
58+
elif [ $percentage -le 50 -a $percentage -ge 16 ];then
59+
printf $medium_charge_icon
60+
elif [ "$percentage" == "" ];then
61+
printf $full_charge_icon_default # assume it's a desktop
62+
else
63+
printf $low_charge_icon
64+
fi
4365
elif [[ $status =~ (attached) ]]; then
4466
printf "$attached_icon"
4567
fi

0 commit comments

Comments
 (0)