Skip to content

Commit

Permalink
improve battery segment
Browse files Browse the repository at this point in the history
  • Loading branch information
embe221ed committed Nov 7, 2023
1 parent b17701c commit cab0747
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions segments/battery.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
# 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_HEARTS_DEFAULT=5
TMUX_POWERLINE_SEG_BATTERY_NUM_BATTERIES_DEFAULT=5

HEART_FULL=""
HEART_EMPTY=""
BATTERY_FULL="󱊣"
BATTERY_MED="󱊢"
BATTERY_EMPTY="󱊡"
BATTERY_CHARGE="󰂄"
ADAPTER="󰚥"

This comment has been minimized.

Copy link
@adamk33n3r

adamk33n3r Jun 14, 2024

What are these characters? My computer shows ? boxes for all of them :/

This comment has been minimized.

Copy link
@xx4h

xx4h Jun 30, 2024

Collaborator

If you see weird chars, you don't have a supported font (e.g. nerdfonts) installed.

You may want to check this discussion as well: #349 (reply in thread)

This comment has been minimized.

Copy link
@adamk33n3r

adamk33n3r Jul 17, 2024

Oh shoot, for some reason I thought I was supposed to be using powerline fonts which had most of them. I hadn't heard of nerd fonts, but after installing them it works thank you!


generate_segmentrc() {
read -d '' rccontents << EORC
# How to display battery remaining. Can be {percentage, cute}.
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_HEARTS_DEFAULT}"
export TMUX_POWERLINE_SEG_BATTERY_NUM_HEARTS="${TMUX_POWERLINE_SEG_BATTERY_NUM_BATTERIES_DEFAULT}"
EORC
echo "$rccontents"
}
Expand All @@ -23,11 +26,14 @@ run_segment() {
else
battery_status=$(__battery_linux)
fi
[ -z "$battery_status" ] && return
if [ -z "$battery_status" ]; then
echo "$ADAPTER "
return
fi

case "$TMUX_POWERLINE_SEG_BATTERY_TYPE" in
"percentage")
output="${HEART_FULL} ${battery_status}%"
output="${battery_status}%"
;;
"cute")
output=$(__cutinate $battery_status)
Expand All @@ -42,7 +48,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_HEARTS_DEFAULT}"
export TMUX_POWERLINE_SEG_BATTERY_NUM_HEARTS="${TMUX_POWERLINE_SEG_BATTERY_NUM_BATTERIES_DEFAULT}"
fi
}

Expand All @@ -63,17 +69,21 @@ __battery_osx() {
export fully_charged=$value;;
esac
if [[ -n $maxcap && -n $curcap && -n $extconnect ]]; then
if [[ "$curcap" == "$maxcap" || "$fully_charged" == "Yes" && $extconnect == "Yes" ]]; then
charge=`pmset -g batt | grep -o "[0-9][0-9]*\%" | rev | cut -c 2- | rev`
if [[ ("$fully_charged" == "Yes" || $charge -eq 100) && $extconnect == "Yes" ]]; then
return
fi
charge=`pmset -g batt | grep -o "[0-9][0-9]*\%" | rev | cut -c 2- | rev`
if [[ "$extconnect" == "Yes" ]]; then
echo "$charge"
echo "$BATTERY_CHARGE $charge"
else
if [[ $charge -lt 50 ]]; then
echo -n "#[fg=red]"
echo -n "#[fg=#ff0000]"
echo "$BATTERY_EMPTY $charge"
elif [[ $charge -lt 80 ]]; then
echo "$BATTERY_MED $charge"
else
echo "$BATTERY_FULL $charge"
fi
echo "$charge"
fi
break
fi
Expand Down Expand Up @@ -129,9 +139,9 @@ __battery_osx() {

for i in `seq $TMUX_POWERLINE_SEG_BATTERY_NUM_HEARTS`; do
if [ $perc -lt 99 ]; then
echo -n $HEART_EMPTY
echo -n $BATTERY_EMPTY
else
echo -n $HEART_FULL
echo -n $BATTERY_FULL
fi
echo -n " "
perc=$(( $perc + $inc ))
Expand All @@ -144,10 +154,10 @@ __battery_osx() {
if [ $bn -gt $bf ]; then
bn=$bf
fi
echo $(( 100 * $bn / $bf ))
echo "$BATTERY_MED $(( 100 * $bn / $bf ))"
}

__freebsd_get_bat() {
echo "$(sysctl -n hw.acpi.battery.life)"
echo "$BATTER_MED $(sysctl -n hw.acpi.battery.life)"

}

2 comments on commit cab0747

@adamk33n3r
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit broke cute because of the $BATTERY_MED in the _get_bat functions

@xx4h
Copy link
Collaborator

@xx4h xx4h commented on cab0747 Jun 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you open an Issue for that?

Please sign in to comment.