-
Notifications
You must be signed in to change notification settings - Fork 39
Added support for multiple batteries #48
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ battery usage: | |
| -z output zsh prompt format | ||
| -e don't output the emoji | ||
| -a output ascii instead of spark | ||
| -b battery path default: /sys/class/power_supply/BAT0 | ||
| -b battery path, list default: /sys/class/power_supply/BAT0 | ||
| -p use pmset (more accurate) | ||
| colors: tmux zsh | ||
| -g <color> good battery level default: 1;32 | green | 64 | ||
|
|
@@ -75,26 +75,18 @@ battery_charge() { | |
| fi | ||
| ;; | ||
| "Linux") | ||
| case $(cat /etc/*-release) in | ||
| *"Arch Linux"*|*"Ubuntu"*|*"openSUSE"*) | ||
| battery_state=$(cat $battery_path/energy_now) | ||
| battery_full=$battery_path/energy_full | ||
| battery_current=$battery_path/energy_now | ||
| ;; | ||
| *) | ||
| battery_state=$(cat $battery_path/status) | ||
| battery_full=$battery_path/charge_full | ||
| battery_current=$battery_path/charge_now | ||
| ;; | ||
| esac | ||
| if [ $battery_state == 'Discharging' ]; then | ||
| BATT_CONNECTED=0 | ||
| else | ||
| BATT_CONNECTED=1 | ||
| fi | ||
| now=$(cat $battery_current) | ||
| full=$(cat $battery_full) | ||
| BATT_PCT=$((100 * $now / $full)) | ||
| for battery_path in ${battery_paths[@]}; do | ||
| battery_state=$(cat $battery_path/status) | ||
| if [[ $battery_state == "Charging" || $battery_full == "Full" ]]; then | ||
| BATT_CONNECTED=1 | ||
| fi | ||
| battery_full=$battery_path/energy_full | ||
| battery_current=$battery_path/energy_now | ||
|
Comment on lines
+78
to
+84
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. Hello, quick question: Why did you remove the
Author
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. Hi, i wasn’t sure about the differences in the first place, but on my test machines (Arch and Ubuntu) both paths were the same as the second case. |
||
|
|
||
| now=$(($now + $(cat $battery_current))) | ||
| full=$(($full + $(cat $battery_full))) | ||
| done | ||
| BATT_PCT=$((100 * $now / $full)) | ||
| ;; | ||
| esac | ||
| } | ||
|
|
@@ -153,7 +145,7 @@ print_status() { | |
| rounded_n=$(( $barlength * $BATT_PCT / 100 + 1)) | ||
|
|
||
| # Creates the bar | ||
| GRAPH=$(printf "[%-${barlength}s]" "${ascii_bar:0:rounded_n}") | ||
| GRAPH=$(printf "[%-${barlength}s] %s" "${ascii_bar:0:rounded_n}" "$GRAPH") | ||
| fi | ||
|
|
||
| if ((output_tmux)); then | ||
|
|
@@ -200,14 +192,10 @@ while getopts ":g:m:w:tzeab:p" opt; do | |
| ;; | ||
| b) | ||
| if [ -d $OPTARG ]; then | ||
| battery_path=$OPTARG | ||
| else | ||
| >&2 echo "Battery not found, trying to use default path..." | ||
| if [ ! -d $battery_path ]; then | ||
| >&2 echo "Default battery path is also unreachable" | ||
| exit 1 | ||
| fi | ||
| fi | ||
| battery_paths+=("$OPTARG") | ||
| else | ||
| >&2 echo "Could not find battery at path \"$OPTARG\"" | ||
| fi | ||
| ;; | ||
| \?) | ||
| echo "Invalid option: -$OPTARG" | ||
|
|
@@ -219,6 +207,13 @@ while getopts ":g:m:w:tzeab:p" opt; do | |
| ;; | ||
| esac | ||
| done | ||
| if [ -z $battery_paths ]; then | ||
| if [ ! -d $battery_path ]; then | ||
| >&2 echo "Default battery path is unreachable" | ||
| exit 1 | ||
| fi | ||
| battery_paths=("$battery_path") | ||
| fi | ||
|
|
||
| battery_charge | ||
| apply_colors | ||
|
|
||
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.
We do actually rely on this right?
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.
Yes but now it defaults to 0 unless one of the batteries is indicating that it is charging or full