@@ -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,40 @@ battery_status()
153159
154160main ()
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+ IFS=$' \n ' read -rd ' ' -a percs <<< " $bat_perc"
182+ IFS=$' \n ' read -rd ' ' -a stats <<< " $(get_battery_status)"
183+ IFS=$' \n ' read -rd ' ' -a lbls <<< " $bat_label"
184+ num_bats=${# percs[@]}
185+ show_bat_label=$( get_tmux_option " @dracula-show-battery-status" false)
186+ for (( i= 0 ; i< num_bats; i++ )) ; do
187+ if [[ i -gt 0 ]]; then
188+ echo -n " $( get_tmux_option " @dracula-battery-separator" " ; " ) "
189+ fi
190+ echo -n " ${lbls[$i]} "
191+ if $show_bat_label ; then
192+ echo -n " $( parse_battery_status " ${percs[$i]} " " ${stats[$i]} " ) "
193+ fi
194+ echo -n " ${percs[$i]} %"
195+ done
188196 fi
189197}
190198
0 commit comments