Merge pull request #397 from dylanaraps/bat
Battery: [Linux] Rewrite battery
This commit is contained in:
commit
37662132e7
|
@ -161,21 +161,6 @@ gtk2="on"
|
||||||
gtk3="on"
|
gtk3="on"
|
||||||
|
|
||||||
|
|
||||||
# Battery
|
|
||||||
|
|
||||||
# Which battery to display.
|
|
||||||
# By default we display all batteries.
|
|
||||||
# NOTE: Only works on Linux.
|
|
||||||
# --battery_num all, 0, 1, 2, etc
|
|
||||||
battery_num="all"
|
|
||||||
|
|
||||||
# Whether or not to print each battery on the same line.
|
|
||||||
# By default each battery gets its own line and title.
|
|
||||||
# NOTE: Only works on Linux.
|
|
||||||
# --battery_shorthand on, off
|
|
||||||
battery_shorthand="off"
|
|
||||||
|
|
||||||
|
|
||||||
# IP Address
|
# IP Address
|
||||||
|
|
||||||
# Website to ping for the public IP
|
# Website to ping for the public IP
|
||||||
|
|
47
neofetch
47
neofetch
|
@ -1618,44 +1618,25 @@ getdisk() {
|
||||||
getbattery() {
|
getbattery() {
|
||||||
case "$os" in
|
case "$os" in
|
||||||
"Linux")
|
"Linux")
|
||||||
if [ "$(ls /sys/class/power_supply/)" ]; then
|
# We use 'prin' here and exit the function early so that we can
|
||||||
# Set the index to the battery number.
|
# do multi battery support with a single battery per line.
|
||||||
case "$battery_num" in
|
if [ -f /sys/class/power_supply/**/capacity ]; then
|
||||||
"all") battery_num="*" index=0 ;;
|
for bat in "/sys/class/power_supply/BAT"*; do
|
||||||
*) index="$battery_num" ;;
|
capacity="$(< ${bat}/capacity)"
|
||||||
esac
|
status="$(< ${bat}/status)"
|
||||||
|
battery="${capacity}% [${status}]"
|
||||||
|
|
||||||
batteries=("$(cat /sys/class/power_supply/BAT$battery_num/capacity)")
|
|
||||||
battery_state=("$(cat /sys/class/power_supply/BAT${battery_num}/status)")
|
|
||||||
|
|
||||||
# Get the subtitle and reassign it so it doesn't change.
|
|
||||||
title="$subtitle"
|
|
||||||
|
|
||||||
# If shorthand is on, print each value on the same line
|
|
||||||
if [ "$battery_shorthand" == "on" ]; then
|
|
||||||
battery="${batteries[*]}"
|
|
||||||
battery="${battery// /%, }"
|
|
||||||
battery="${battery}%"
|
|
||||||
|
|
||||||
else
|
|
||||||
if [ "${#batteries[@]}" -gt 1 ]; then
|
|
||||||
unset battery
|
|
||||||
|
|
||||||
# Print each battery on a separate line.
|
|
||||||
for bat in "${batteries[@]}"; do
|
|
||||||
case "$battery_display" in
|
case "$battery_display" in
|
||||||
"bar") prin "${title}${index:-0}" "$(bar "${bat/'%'}" 100)" ;;
|
"bar") battery="$(bar "$capacity" 100)" ;;
|
||||||
"infobar") prin "${title}${index:-0}" "${bat}% $(bar "${bat/'%'}" 100)" ;;
|
"infobar") battery+=" $(bar "$capacity" 100)" ;;
|
||||||
"barinfo") prin "${title}${index:-0}" "$(bar "${bat/'%'}" 100) ${bat}%" ;;
|
"barinfo") battery="$(bar "$capacity" 100) ${battery}" ;;
|
||||||
*) prin "${title}${index:-0}" "${bat}%" ;;
|
|
||||||
esac
|
esac
|
||||||
index="$((index+=1))"
|
|
||||||
|
prin "${subtitle}${bat: -1}" "$battery"
|
||||||
done
|
done
|
||||||
|
fi
|
||||||
|
unset battery
|
||||||
return
|
return
|
||||||
fi
|
|
||||||
battery="${batteries[0]}%"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"BSD")
|
"BSD")
|
||||||
|
|
Reference in New Issue