Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to display battery status as hearts in battery.sh #447

Merged
merged 4 commits into from
Oct 10, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions segments/battery.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
# 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 +14,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 @@ -39,6 +41,9 @@ run_segment() {
"cute")
output=$(__cutinate "$battery_status")
;;
"hearts")
output=$(__generate_hearts "$battery_status")
nikunjmathur08 marked this conversation as resolved.
Show resolved Hide resolved
;;
esac
if [ -n "$output" ]; then
echo "$output"
Expand All @@ -50,7 +55,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 @@ -134,6 +139,21 @@ __cutinate() {
done
}

__generate_hearts() {
perc=$1
num_hearts=$TMUX_POWERLINE_SEG_BATTERY_NUM_HEARTS
hearts_output=""

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

__linux_get_bat() {
bf=$(cat "$BAT_FULL")
bn=$(cat "$BAT_NOW")
Expand Down