Skip to content

Commit

Permalink
Restore hearts display for battery status and apply feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nikunjmathur08 committed Oct 7, 2024
1 parent d375f64 commit f014e55
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions segments/battery.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
# LICENSE This code is not under the same license as the rest of the project as it's "stolen". It's cloned from https://github.com/richoH/dotfiles/blob/master/bin/battery and just some modifications are done so it works for my laptop. Check that URL for more recent versions.

TMUX_POWERLINE_SEG_BATTERY_TYPE_DEFAULT="percentage"
TMUX_POWERLINE_SEG_BATTERY_NUM_BATTERIES_DEFAULT=5
TMUX_POWERLINE_SEG_BATTERY_NUM_HEARTS_DEFAULT=5


HEART_FULL=""
HEART_EMPTY=""
BATTERY_FULL="󱊣"
BATTERY_MED="󱊢"
BATTERY_EMPTY="󱊡"
Expand All @@ -12,10 +15,10 @@ ADAPTER="󰚥"

generate_segmentrc() {
read -r -d '' rccontents <<EORC
# How to display battery remaining. Can be {percentage, cute}.
# How to display battery remaining. Can be {percentage, cute, hearts}.
export TMUX_POWERLINE_SEG_BATTERY_TYPE="${TMUX_POWERLINE_SEG_BATTERY_TYPE_DEFAULT}"
# How may hearts to show if cute indicators are used.
export TMUX_POWERLINE_SEG_BATTERY_NUM_HEARTS="${TMUX_POWERLINE_SEG_BATTERY_NUM_BATTERIES_DEFAULT}"
export TMUX_POWERLINE_SEG_BATTERY_NUM_HEARTS="${TMUX_POWERLINE_SEG_BATTERY_NUM_HEARTS_DEFAULT}"
EORC
echo "$rccontents"
}
Expand All @@ -41,6 +44,7 @@ run_segment() {
;;
"hearts")
output=$(__generate_hearts "$battery_status")
;;
esac
if [ -n "$output" ]; then
echo "$output"
Expand All @@ -52,7 +56,7 @@ __process_settings() {
export TMUX_POWERLINE_SEG_BATTERY_TYPE="${TMUX_POWERLINE_SEG_BATTERY_TYPE_DEFAULT}"
fi
if [ -z "$TMUX_POWERLINE_SEG_BATTERY_NUM_HEARTS" ]; then
export TMUX_POWERLINE_SEG_BATTERY_NUM_HEARTS="${TMUX_POWERLINE_SEG_BATTERY_NUM_BATTERIES_DEFAULT}"
export TMUX_POWERLINE_SEG_BATTERY_NUM_HEARTS="${TMUX_POWERLINE_SEG_BATTERY_NUM_HEARTS_DEFAULT}"
fi
}

Expand Down Expand Up @@ -143,9 +147,9 @@ __generate_hearts() {

for i in $(seq 1 "$num_hearts"); do
if [ "$perc" -ge $((i * 100 / num_hearts)) ]; then
hearts_output+="$BATTERY_FULL "
hearts_output+="$HEART_FULL "
else
hearts_output+="$BATTERY_EMPTY "
hearts_output+="$HEART_EMPTY "
fi
done
echo "$hearts_output"
Expand Down

0 comments on commit f014e55

Please sign in to comment.