From b23ccd6709310c7b643cb6e1e8e7970dd707df2f Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 26 Oct 2016 17:56:50 +1100 Subject: [PATCH 1/2] Battery: [Linux] Rewrite battery --- neofetch | 51 ++++++++++++++++----------------------------------- 1 file changed, 16 insertions(+), 35 deletions(-) diff --git a/neofetch b/neofetch index a1d49fff..44061111 100755 --- a/neofetch +++ b/neofetch @@ -1618,44 +1618,25 @@ getdisk() { getbattery() { case "$os" in "Linux") - if [ "$(ls /sys/class/power_supply/)" ]; then - # Set the index to the battery number. - case "$battery_num" in - "all") battery_num="*" index=0 ;; - *) index="$battery_num" ;; - esac + # We use 'prin' here and exit the function early so that we can + # do multi battery support with a single battery per line. + if [ -f /sys/class/power_supply/**/capacity ]; then + for bat in "/sys/class/power_supply/BAT"*; do + capacity="$(< ${bat}/capacity)" + 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)") + case "$battery_display" in + "bar") battery="$(bar "$capacity" 100)" ;; + "infobar") battery+=" $(bar "$capacity" 100)" ;; + "barinfo") battery="$(bar "$capacity" 100) ${battery}" ;; + esac - # 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 - "bar") prin "${title}${index:-0}" "$(bar "${bat/'%'}" 100)" ;; - "infobar") prin "${title}${index:-0}" "${bat}% $(bar "${bat/'%'}" 100)" ;; - "barinfo") prin "${title}${index:-0}" "$(bar "${bat/'%'}" 100) ${bat}%" ;; - *) prin "${title}${index:-0}" "${bat}%" ;; - esac - index="$((index+=1))" - done - return - fi - battery="${batteries[0]}%" - fi + prin "${subtitle}${bat: -1}" "$battery" + done fi + unset battery + return ;; "BSD") From 72de6686416f5e43062cf876676a0757284a74ff Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 26 Oct 2016 17:59:03 +1100 Subject: [PATCH 2/2] Battery: [Linux] Remove old options --- config/config | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/config/config b/config/config index eeecf851..7390acac 100644 --- a/config/config +++ b/config/config @@ -161,21 +161,6 @@ gtk2="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 # Website to ping for the public IP