-
Notifications
You must be signed in to change notification settings - Fork 98
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
base: master
Are you sure you want to change the base?
Conversation
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 | ||
} |
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.
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)
local percentage=$(get_percent) | ||
percentage=$(echo ${percentage} | sed -e 's/%//g') |
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.
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" |
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.
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" |
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.
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?
Closes #90
Added a text version. Going to try and make it more obvious by changing the foreground color to red?