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

feat: add mac battery item #505

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all 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
30 changes: 30 additions & 0 deletions functions/_tide_item_mac_battery.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function _tide_item_mac_battery
set -l info (pmset -g batt | awk 'NR==2 {gsub(/;/,""); print $3 " " $4}')
set -l percent (string match -rg '(\d+)%\s*\w+' $info)
set -l state (string match -rg '\d+%\s*(\w+)' $info)
set -l icons $tide_mac_battery_icons
set -l colors $tide_mac_battery_colors

# icons = [0%, 10%, 20%, 30%, 40%, 50%, 60%, 70%, 80%, 90%, 100%, charging]
# colors = [low, normal, charging]

if test $state != discharging # plugged in, either charging or charged
set -f icon $icons[12]
else
set -l icon_type (math round $percent / 10)
set -l icon_idx (math $icon_type + 1)

set -f icon $icons[$icon_idx]
end

if test $state != discharging
set_color $colors[3]
else if test $percent -le 20
set_color $colors[1]
else
set_color $colors[2]
end

printf ' %s %s%%' $icon $percent
set_color normal
end