-
Notifications
You must be signed in to change notification settings - Fork 7
Add vbattery and hbattery prompt items #28
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
Open
jose1711
wants to merge
1
commit into
plttn:main
Choose a base branch
from
jose1711:battery_item_plttn
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| function _tide_item_hbattery | ||
| switch $tide_battery_method | ||
| case termux | ||
| set -l termux_bat_out (termux-battery-status) | ||
| set -f bat_capacity (string match -rg 'percentage": ([0-9]*)' $termux_bat_out) | ||
| set -f bat_status (string match -rg '"status": "([^"]*)"' $termux_bat_out) | ||
| case sysfs | ||
| if set -q tide_battery_sysfs_name | ||
| set -f bat_capacity (cat /sys/class/power_supply/$tide_battery_sysfs_name/capacity) | ||
| set -f bat_status (cat /sys/class/power_supply/$tide_battery_sysfs_name/status) | ||
| else | ||
| set -l battery_name /sys/class/power_supply/BAT* | ||
| if count $battery_name >/dev/null | ||
| set -f bat_capacity (cat $battery_name/capacity)[1] | ||
| set -f bat_status (cat $battery_name/status)[1] | ||
| end | ||
| end | ||
| case '*' | ||
| set -l upower_out (upower -b) | ||
| set -f bat_capacity (string match -rg 'percentage: *([0-9]*)' $upower_out) | ||
| set -f bat_status (string match -rg 'state: *(.*)' $upower_out) | ||
| end | ||
|
|
||
| test -n "$bat_capacity" || return | ||
|
|
||
| # 0-19 20-39 40-59 60-79 80-99 100 | ||
| set -f battery_symbols '' '' '' '' '' '' | ||
|
|
||
| switch (string lower $bat_status) | ||
| case 'not charging' 'fully charged' fully-charged | ||
| _tide_print_item hbattery '' | ||
| return | ||
| case discharging | ||
| if test $bat_capacity -lt $tide_battery_critical_threshold | ||
| set -fx tide_battery_color $tide_battery_color_critical | ||
| else if test $bat_capacity -lt $tide_battery_low_threshold | ||
| set -fx tide_battery_color $tide_battery_color_low | ||
| end | ||
| end | ||
|
|
||
| set -l symbol_index (math -s0 "$bat_capacity / 20 + 1") | ||
| set -l battery_symbol $battery_symbols[$symbol_index] | ||
|
|
||
| if string match charging (string lower $bat_status) -q | ||
| _tide_print_item hbattery "$battery_symbol " | ||
| else | ||
| _tide_print_item hbattery $battery_symbol | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| function _tide_item_vbattery | ||
| switch $tide_battery_method | ||
| case termux | ||
| set -l termux_bat_out (termux-battery-status) | ||
| set -f bat_capacity (string match -rg 'percentage": ([0-9]*)' $termux_bat_out) | ||
| set -f bat_status (string match -rg '"status": "([^"]*)"' $termux_bat_out) | ||
| case sysfs | ||
| if set -q tide_battery_sysfs_name | ||
| set -f bat_capacity (cat /sys/class/power_supply/$tide_battery_sysfs_name/capacity) | ||
| set -f bat_status (cat /sys/class/power_supply/$tide_battery_sysfs_name/status) | ||
| else | ||
| set -l battery_name /sys/class/power_supply/BAT* | ||
| if count $battery_name >/dev/null | ||
| set -f bat_capacity (cat $battery_name/capacity)[1] | ||
| set -f bat_status (cat $battery_name/status)[1] | ||
| end | ||
| end | ||
| case '*' | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here as well. Additionally, if combined into a single item with a switcher for style, this avoids duplicating logic in case it needs to be updated in the future |
||
| set -l upower_out (upower -b) | ||
| set -f bat_capacity (string match -rg 'percentage: *([0-9]*)' $upower_out) | ||
| set -f bat_status (string match -rg 'state: *(.*)' $upower_out) | ||
| end | ||
|
|
||
| test -n "$bat_capacity" || return | ||
|
|
||
| switch (string lower $bat_status) | ||
| case 'not charging' 'fully charged' | ||
| _tide_print_item vbattery '' | ||
| return | ||
| case charging | ||
| # 0-4 5-14 15-24 25-34 35-44 45-54 55-64 65-74 75-84 85-94 95-100 | ||
| set -f battery_symbols '' '' '' '' '' '' '' '' '' '' '' | ||
| case discharging | ||
| set -f battery_symbols '' '' '' '' '' '' '' '' '' '' '' | ||
| if test $bat_capacity -lt $tide_battery_critical_threshold | ||
| set -fx tide_battery_color $tide_battery_color_critical | ||
| else if test $bat_capacity -lt $tide_battery_low_threshold | ||
| set -fx tide_battery_color $tide_battery_color_low | ||
| end | ||
| case '*' | ||
| _tide_print_item vbattery '' | ||
| return | ||
| end | ||
|
|
||
| set -l symbol_index (math -s0 -m round "$bat_capacity / 10 + 1") | ||
| set -l battery_symbol $battery_symbols[$symbol_index] | ||
|
|
||
| _tide_print_item vbattery $battery_symbol | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| # RUN: %fish %s | ||
| source (status dirname)/../functions/_tide_parent_dirs.fish | ||
| source (status dirname)/../functions/_tide_print_item.fish | ||
| source (status dirname)/../functions/_tide_item_vbattery.fish | ||
| source (status dirname)/../functions/_tide_item_hbattery.fish | ||
|
|
||
| function _tide_decolor | ||
| string replace --all -r '\e(\[[\d;]*|\(B\e\[)m(\co)?' '' "$argv" | ||
| end | ||
|
|
||
| set -g _tide_side right | ||
| set -g _tide_pad '' | ||
| set -g tide_right_prompt_separator_diff_color '' | ||
| set -g tide_right_prompt_separator_same_color '' | ||
| set -g tide_right_prompt_prefix '' | ||
|
|
||
| _tide_parent_dirs | ||
|
|
||
| set -lx tide_battery_color_critical red | ||
| set -lx tide_battery_color_low yellow | ||
| set -lx tide_battery_critical_threshold 15 | ||
| set -lx tide_battery_low_threshold 40 | ||
| set -lx tide_battery_method '' | ||
|
|
||
| # ── vbattery ────────────────────────────────────────────────────────────────── | ||
|
|
||
| function _vbattery | ||
| _tide_decolor (_tide_item_vbattery) | ||
| end | ||
|
|
||
| set -lx tide_vbattery_bg_color normal | ||
| set -lx tide_vbattery_color normal | ||
|
|
||
| function upower | ||
| echo 'No battery found' | ||
| end | ||
| _vbattery # CHECK: | ||
|
|
||
| function upower | ||
| echo 'percentage: 50' | ||
| echo 'state: discharging' | ||
| end | ||
| _vbattery # CHECK: | ||
|
|
||
| function upower | ||
| echo 'percentage: 20' | ||
| echo 'state: discharging' | ||
| end | ||
| _vbattery # CHECK: | ||
|
|
||
| function upower | ||
| echo 'percentage: 10' | ||
| echo 'state: discharging' | ||
| end | ||
| _vbattery # CHECK: | ||
|
|
||
| function upower | ||
| echo 'percentage: 50' | ||
| echo 'state: charging' | ||
| end | ||
| _vbattery # CHECK: | ||
|
|
||
| function upower | ||
| echo 'percentage: 100' | ||
| echo 'state: fully charged' | ||
| end | ||
| _vbattery # CHECK: | ||
|
|
||
| function upower | ||
| echo 'percentage: 100' | ||
| echo 'state: not charging' | ||
| end | ||
| _vbattery # CHECK: | ||
|
|
||
| function upower | ||
| echo 'percentage: 50' | ||
| echo 'state: unknown' | ||
| end | ||
| _vbattery # CHECK: | ||
|
|
||
| set -lx tide_battery_method termux | ||
| function termux-battery-status | ||
| echo '{"percentage": 75, "status": "CHARGING"}' | ||
| end | ||
| _vbattery # CHECK: | ||
|
|
||
| # ── hbattery ────────────────────────────────────────────────────────────────── | ||
|
|
||
| set -lx tide_battery_method '' | ||
|
|
||
| function _hbattery | ||
| _tide_decolor (_tide_item_hbattery) | ||
| end | ||
|
|
||
| set -lx tide_hbattery_bg_color normal | ||
| set -lx tide_hbattery_color normal | ||
|
|
||
| function upower | ||
| echo 'No battery found' | ||
| end | ||
| _hbattery # CHECK: | ||
|
|
||
| function upower | ||
| echo 'percentage: 10' | ||
| echo 'state: discharging' | ||
| end | ||
| _hbattery # CHECK: | ||
|
|
||
| function upower | ||
| echo 'percentage: 30' | ||
| echo 'state: discharging' | ||
| end | ||
| _hbattery # CHECK: | ||
|
|
||
| function upower | ||
| echo 'percentage: 60' | ||
| echo 'state: discharging' | ||
| end | ||
| _hbattery # CHECK: | ||
|
|
||
| function upower | ||
| echo 'percentage: 80' | ||
| echo 'state: charging' | ||
| end | ||
| _hbattery # CHECK: | ||
|
|
||
| function upower | ||
| echo 'percentage: 80' | ||
| echo 'state: discharging' | ||
| end | ||
| _hbattery # CHECK: | ||
|
|
||
| function upower | ||
| echo 'percentage: 100' | ||
| echo 'state: fully charged' | ||
| end | ||
| _hbattery # CHECK: | ||
|
|
||
| function upower | ||
| echo 'percentage: 100' | ||
| echo 'state: not charging' | ||
| end | ||
| _hbattery # CHECK: |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will error on macOS because we don't have a guard here.