Skip to content

Commit 4564d62

Browse files
multi battery display
1 parent e177157 commit 4564d62

File tree

2 files changed

+39
-24
lines changed

2 files changed

+39
-24
lines changed

docs/CONFIG.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ these settings will introduce the following icons:
223223
if you have no battery and would like the widget to hide in that case, set the following:
224224

225225
```bash
226+
set -g @dracula-battery-label false
226227
set -g @dracula-no-battery-label false
227228
```
228229

@@ -232,11 +233,16 @@ alternatively, if you have no battery and would like a nerdfont icon to indicate
232233
set -g @dracula-no-battery-label ""
233234
```
234235

235-
if you only want to hide the battery widget on a desktop pc, set the following:
236+
in case you have multiple batteries:
236237

238+
the default battery label is only displayed in the very front.
239+
you can specify multiple battery labels by splitting them with `\n` like so:
237240
```bash
238-
# default is false
239-
set -g @dracula-battery-hide-on-desktop true
241+
set -g @dracula-battery-label "1:\n2:"
242+
```
243+
additionally you can specify the separator between each battery like so:
244+
```bash
245+
set -g @dracula-battery-separator "; "
240246
```
241247

242248
### compact-alt - [up](#table-of-contents)

scripts/battery.sh

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ battery_percent()
6161
esac
6262
}
6363

64-
battery_status()
64+
get_battery_status()
6565
{
6666
# Check OS
6767
case $(uname -s) in
@@ -84,9 +84,15 @@ battery_status()
8484
*)
8585
;;
8686
esac
87+
echo "$status"
88+
}
8789

88-
tmp_bat_perc=$(battery_percent)
89-
bat_perc="${tmp_bat_perc%\%}"
90+
parse_battery_status()
91+
{
92+
# $1 is battery_percent
93+
bat_perc="$1"
94+
# $2 is get_battery_status
95+
status="$2"
9096

9197
case $status in
9298
discharging|Discharging)
@@ -153,38 +159,41 @@ battery_status()
153159

154160
main()
155161
{
162+
# get left most custom label
156163
bat_label=$(get_tmux_option "@dracula-battery-label" "")
157164
if [ "$bat_label" == false ]; then
158165
bat_label=""
159166
fi
160167

168+
# get label for when there is no battery
161169
no_bat_label=$(get_tmux_option "@dracula-no-battery-label" "AC")
162170
if [ "$no_bat_label" == false ]; then
163171
no_bat_label=""
164172
fi
165173

166-
show_bat_label=$(get_tmux_option "@dracula-show-battery-status" false)
167-
if $show_bat_label; then
168-
bat_stat=$(battery_status)
169-
else
170-
bat_stat=""
171-
fi
172-
173174
bat_perc=$(battery_percent)
175+
bat_perc="${bat_perc%\%}"
174176

175-
hide_on_desktop=$(get_tmux_option "@dracula-battery-hide-on-desktop" false)
176-
# If no battery percent and the feature flag is enabled, hide the widget completely
177-
if $hide_on_desktop && [ -z "$bat_perc" ]; then
178-
echo ""
179-
return
180-
fi
181-
182-
if [ -z "$bat_stat" ]; then # Test if status is empty or not
183-
echo "$bat_label $bat_perc"
184-
elif [ -z "$bat_perc" ]; then # In case it is a desktop with no battery percent, only AC power
177+
# display widget
178+
if [ -z "$bat_perc" ]; then # In case it is a desktop with no battery percent, only AC power
185179
echo "$no_bat_label"
186180
else
187-
echo "$bat_label$bat_stat $bat_perc"
181+
num_bats=$(wc -l <<< "$bat_perc")
182+
183+
IFS=$'\n' read -rd '' -a percs <<<"$bat_perc"
184+
IFS=$'\n' read -rd '' -a stats <<<"$(get_battery_status)"
185+
IFS=$'\n' read -rd '' -a lbls <<<"$bat_label"
186+
show_bat_label=$(get_tmux_option "@dracula-show-battery-status" false)
187+
for ((i=0; i<num_bats; i++)); do
188+
if [[ i -gt 0 ]]; then
189+
echo -n "$(get_tmux_option "@dracula-battery-separator" "; ")"
190+
fi
191+
echo -n "${lbls[$i]}"
192+
if $show_bat_label; then
193+
echo -n "$(parse_battery_status "${percs[$i]}" "${stats[$i]}") "
194+
fi
195+
echo -n "${percs[$i]}%"
196+
done
188197
fi
189198
}
190199

0 commit comments

Comments
 (0)