Skip to content

Commit

Permalink
Merge pull request #276 from Theoreticallyhugo/master
Browse files Browse the repository at this point in the history
feature/ better battery indication
  • Loading branch information
ethancedwards8 authored Aug 19, 2024
2 parents b778a57 + 4e0fb6b commit 36217d1
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 7 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ Configuration and options can be found at [draculatheme.com/tmux](https://dracul
- List of windows with the current window highlighted
- When prefix is enabled, a smiley face turns from green to yellow
- When charging, 'AC' is displayed
- Alternatively show battery level and whether its charging next to percentage by setting:
`set -g @dracula-battery-label false`
`set -g @dracula-show-battery-status true`
- If forecast information is available, a β˜€, ☁, β˜‚, or ❄ unicode character corresponding with the forecast is displayed alongside the temperature
- Info if the Panes are synchronized
- Spotify playback (needs the tool spotify-tui installed)
Expand Down
63 changes: 56 additions & 7 deletions scripts/battery.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,57 @@ battery_status()
;;
esac

tmp_bat_perc=$(battery_percent)
bat_perc="${tmp_bat_perc%\%}"

case $status in
discharging|Discharging)
echo ''
# discharging, no AC
declare -A battery_labels=(
[0]="σ°‚Ž"
[10]="󰁺"
[20]="󰁻"
[30]="󰁼"
[40]="󰁽"
[50]="󰁾"
[60]="󰁿"
[70]="σ°‚€"
[80]="󰂁"
[90]="σ°‚‚"
[100]="󰁹"
)
echo "${battery_labels[$((bat_perc/10*10))]:-󰂃}"
;;
high|Full)
echo ''
echo "󰁹"
;;
charging|Charging)
echo 'AC'
# charging from AC
declare -A battery_labels=(
[0]="ξ€Šσ°‚Ž"
[10]="ξ€Šσ°Ί"
[20]="ξ€Šσ°»"
[30]="ξ€Šσ°Ό"
[40]="ξ€Šσ°½"
[50]="ξ€Šσ°Ύ"
[60]="ξ€Šσ°Ώ"
[70]="ξ€Šσ°‚€"
[80]="ξ€Šσ°‚"
[90]="ξ€Šσ°‚‚"
[100]="ξ€Šσ°Ή"
)
echo "${battery_labels[$((bat_perc/10*10))]:-󰂃}"
;;
ACattached)
# drawing from AC but not charging
echo 'ξ€Š'
;;
finishingcharge)
echo 'ξ€Šσ°Ή'
;;
*)
echo 'AC'
# something wrong...
echo ''
;;
esac
### Old if statements didn't work on BSD, they're probably not POSIX compliant, not sure
Expand All @@ -112,15 +151,25 @@ battery_status()
main()
{
bat_label=$(get_tmux_option "@dracula-battery-label" "β™₯")
bat_stat=$(battery_status)
if [ "$bat_label" ]; then
bat_label=""
fi

show_bat_label=$(get_tmux_option "@dracula-show-battery-status" false)
if $show_bat_label; then
bat_stat=$(battery_status)
else
bat_stat=""
fi

bat_perc=$(battery_percent)

if [ -z "$bat_stat" ]; then # Test if status is empty or not
echo "$bat_label $bat_perc"
elif [ -z "$bat_perc" ]; then # In case it is a desktop with no battery percent, only AC power
echo "$bat_label $bat_stat"
echo ""
else
echo "$bat_label $bat_stat $bat_perc"
echo "$bat_label$bat_stat $bat_perc"
fi
}

Expand Down

0 comments on commit 36217d1

Please sign in to comment.