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

#90 Charging Reminder #91

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

rbharadwaj9
Copy link

Closes #90

Added a text version. Going to try and make it more obvious by changing the foreground color to red?

Comment on lines +7 to +36
get_percent() {
# percentage displayed in the 2nd field of the 2nd row
if command_exists "pmset"; then
pmset -g batt | grep -o "[0-9]\{1,3\}%"
elif command_exists "acpi"; then
acpi -b | grep -m 1 -Eo "[0-9]+%"
elif command_exists "upower"; then
# use DisplayDevice if available otherwise battery
local battery=$(upower -e | grep -E 'battery|DisplayDevice'| tail -n1)
if [ -z "$battery" ]; then
return
fi
local percentage=$(upower -i $battery | awk '/percentage:/ {print $2}')
if [ "$percentage" ]; then
echo ${percentage%.*%}
return
fi
local energy
local energy_full
energy=$(upower -i $battery | awk -v nrg="$energy" '/energy:/ {print nrg+$2}')
energy_full=$(upower -i $battery | awk -v nrgfull="$energy_full" '/energy-full:/ {print nrgfull+$2}')
if [ -n "$energy" ] && [ -n "$energy_full" ]; then
echo $energy $energy_full | awk '{printf("%d%%", ($1/$2)*100)}'
fi
elif command_exists "termux-battery-status"; then
termux-battery-status | jq -r '.percentage' | awk '{printf("%d%%", $1)}'
elif command_exists "apm"; then
apm -l
fi
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than just copy/pasting the print_battery_percentage function from "battery_percentage.sh", I would suggest just calling that script when needed: foo=$($CURRENT_DIR/battery_percentage.sh)

Comment on lines +39 to +40
local percentage=$(get_percent)
percentage=$(echo ${percentage} | sed -e 's/%//g')
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
local percentage=$(get_percent)
percentage=$(echo ${percentage} | sed -e 's/%//g')
local percentage=$($CURRENT_DIR/battery_percentage.sh | sed -e 's/%//g')

I would recommend making use of the existing functions to get the battery percentage and directly piping it through sed rather than doing so in another step.

percentage=$(echo ${percentage} | sed -e 's/%//g')
if [[ $percentage -lt 20 ]]; then
if [[ "$(battery_status)" == "discharging" ]]; then
echo "CHARGE IMMEDIATELY"
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest changing this to be customizable via the config. (You can find examples of this in the "battery_icon_charge.sh" script, among others.)

I would also argue that "CHARGE IMMEDIATELY" is too long of a string for a sane default. Maybe something like "CHRG" instead?

fi
elif [[ $percentage -gt 80 ]]; then
if [[ "$(battery_status)" != "discharging" ]]; then
echo "STOP CHARGING"
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest changing this to be customizable via the config. (You can find examples of this in the "battery_icon_charge.sh" script, among others.)

I would also argue that "STOP CHARGING" is too long of a string for a sane default. Maybe something like "UNPL" instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: Suggest to charge/remove charging at 20% or 80%
2 participants