Skip to content
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
55 changes: 25 additions & 30 deletions battery
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Comment on lines -90 to -94

Copy link
Copy Markdown
Owner

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?

Copy link
Copy Markdown
Author

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

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

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Hello, quick question: Why did you remove the Arch Linux , Ubuntu and openSUSE checks? are these not necessary at all?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand Down