From 5abba17564c3c315eb43d808016dd1c063ff2e05 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 16 Dec 2016 22:32:46 +1100 Subject: [PATCH 01/14] Disk: Rewrite get_disk. --- neofetch | 65 +++++++++++++------------------------------------------- 1 file changed, 15 insertions(+), 50 deletions(-) diff --git a/neofetch b/neofetch index 14fd0315..c12e5334 100755 --- a/neofetch +++ b/neofetch @@ -1539,63 +1539,28 @@ get_term_font() { get_disk() { type -p df >/dev/null 2>&1 || { err "Disk requires 'df' to function. Install 'df' to get disk info."; return; } - # df flags - case "$os" in - "Linux" | "iPhone OS" | "Windows" | "GNU") - df_flags=(-h -l --total) - df_dir="total" + # Get the info for / + disks=($(df /)) - case "$distro" in - "OpenWRT"*) df_flags=(-h); df_dir="rootfs" ;; - "Android"*) return ;; - esac - ;; + # Split the info + disk_used="$((disks[9] / 1024 / 1024))GB" + disk_total="$((disks[8] / 1024 / 1024))GB" - "Mac OS X" | "BSD" | "Haiku") - case "$distro" in - "FreeBSD"* | *"OS X"* | "Mac"*) - df_flags=(-l -H /) - df_dir="/" - ;; + # Handle TB values + (( "${#disk_used}" == 6 )) && disk_used="${disk_used:0:1}.${disk_used:1:1}TB" + (( "${#disk_total}" == 6 )) && disk_total="${disk_total:0:1}.${disk_total:1:1}TB" - *) return ;; - esac - ;; - esac - - # Get the disk info - disk="$(df "${df_flags[@]}" | awk -v dir="$df_dir" '$0 ~ dir {print $2 ":" $3 ":" $5}')" - - # Format the output - disk_used="${disk#*:}" - disk_used="${disk_used%%:*}" - disk_total="${disk%%:*}" - disk_total_per="${disk#*:*:}" + disk_total_per="${disks[11]}" # Put it all together - disk="${disk_used} / ${disk_total} (${disk_total_per})" - - # Add info bar - disk_used="${disk_used/G}" - disk_total="${disk_total/G}" - - # Convert Terabytes to Gigabytes. - if [[ "$disk_display" != "off" ]]; then - disk_used="${disk_used/\.}" - disk_total="${disk_total/\.}" - - [[ "${disk_used: -1}" == "T" ]] && \ - disk_used="$((${disk_used/T} * 100))" - - [[ "${disk_total: -1}" == "T" ]] && \ - disk_total="$((${disk_total/T} * 100))" - fi + disk="${disk_used:+${disk_used} / }${disk_total} ${disk_total_per:+(${disk_total_per})}" + # Bar case "$disk_display" in - "bar") disk="$(bar "${disk_used/'.'*}" "${disk_total/'.'*}")" ;; - "infobar") disk+=" $(bar "${disk_used/'.'*}" "${disk_total/'.'*}")" ;; - "barinfo") disk="$(bar "${disk_used/'.'*}" "${disk_total/'.'*}") $disk" ;; - "perc") disk="$disk_total_per $(bar "${disk_used/'.'*}" "${disk_total/'.'*}")" ;; + "bar") disk="$(bar "${disk_used//[a-z]}" "${disk_total//[a-z]}")" ;; + "infobar") disk+=" $(bar "${disk_used//[a-z]}" "${disk_total//[a-z]}")" ;; + "barinfo") disk="$(bar "${disk_used//[a-z]}" "${disk_total//[a-z]}") $disk" ;; + "perc") disk="$disk_total_per $(bar "${disk_used//[a-z]}" "${disk_total//[a-z]}")" ;; esac } From 4cf108015c39c8f8719237712ff542a2a78d82a2 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 16 Dec 2016 22:40:31 +1100 Subject: [PATCH 02/14] Disk: Remove empty var handling --- neofetch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neofetch b/neofetch index c12e5334..b4fe89af 100755 --- a/neofetch +++ b/neofetch @@ -1553,7 +1553,7 @@ get_disk() { disk_total_per="${disks[11]}" # Put it all together - disk="${disk_used:+${disk_used} / }${disk_total} ${disk_total_per:+(${disk_total_per})}" + disk="${disk_used} / ${disk_total} (${disk_total_per})" # Bar case "$disk_display" in From 17e9fa7774e4d971490db44e834254bc5ab59971 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 16 Dec 2016 22:54:16 +1100 Subject: [PATCH 03/14] Disk: Print filesystem type --- neofetch | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/neofetch b/neofetch index b4fe89af..0553de48 100755 --- a/neofetch +++ b/neofetch @@ -1550,10 +1550,14 @@ get_disk() { (( "${#disk_used}" == 6 )) && disk_used="${disk_used:0:1}.${disk_used:1:1}TB" (( "${#disk_total}" == 6 )) && disk_total="${disk_total:0:1}.${disk_total:1:1}TB" - disk_total_per="${disks[11]}" + # Get the filesystem type + disk_type="[$(awk '$2 == "/" {printf $3; exit}' /etc/fstab)]" + + # Get the usage percentage + disk_total_per="(${disks[11]})" # Put it all together - disk="${disk_used} / ${disk_total} (${disk_total_per})" + disk="${disk_used} / ${disk_total} ${disk_total_per} ${disk_type}" # Bar case "$disk_display" in From 49a96948271fd1e7e05d2b9df07d2a808396cefe Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 16 Dec 2016 23:07:15 +1100 Subject: [PATCH 04/14] Disk: Use '-h' --- neofetch | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/neofetch b/neofetch index 0553de48..6e9af93e 100755 --- a/neofetch +++ b/neofetch @@ -1540,31 +1540,34 @@ get_disk() { type -p df >/dev/null 2>&1 || { err "Disk requires 'df' to function. Install 'df' to get disk info."; return; } # Get the info for / - disks=($(df /)) + disks=($(df -h /)) # Split the info - disk_used="$((disks[9] / 1024 / 1024))GB" - disk_total="$((disks[8] / 1024 / 1024))GB" - - # Handle TB values - (( "${#disk_used}" == 6 )) && disk_used="${disk_used:0:1}.${disk_used:1:1}TB" - (( "${#disk_total}" == 6 )) && disk_total="${disk_total:0:1}.${disk_total:1:1}TB" - - # Get the filesystem type - disk_type="[$(awk '$2 == "/" {printf $3; exit}' /etc/fstab)]" - - # Get the usage percentage + disk_used="${disks[9]}" + disk_total="${disks[8]}" disk_total_per="(${disks[11]})" # Put it all together - disk="${disk_used} / ${disk_total} ${disk_total_per} ${disk_type}" + disk="${disk_used} / ${disk_total} ${disk_total_per}" + + # Convert Terabytes to Gigabytes. + if [[ "$disk_display" != "off" ]]; then + disk_used="${disk_used/\.}" + disk_total="${disk_total/\.}" + + [[ "${disk_used: -1}" == "T" ]] && \ + disk_used="$((${disk_used/T} * 100))" + + [[ "${disk_total: -1}" == "T" ]] && \ + disk_total="$((${disk_total/T} * 100))" + fi # Bar case "$disk_display" in - "bar") disk="$(bar "${disk_used//[a-z]}" "${disk_total//[a-z]}")" ;; - "infobar") disk+=" $(bar "${disk_used//[a-z]}" "${disk_total//[a-z]}")" ;; - "barinfo") disk="$(bar "${disk_used//[a-z]}" "${disk_total//[a-z]}") $disk" ;; - "perc") disk="$disk_total_per $(bar "${disk_used//[a-z]}" "${disk_total//[a-z]}")" ;; + "bar") disk="$(bar "${disk_used/'.'*}" "${disk_total/'.'*}")" ;; + "infobar") disk+=" $(bar "${disk_used/'.'*}" "${disk_total/'.'*}")" ;; + "barinfo") disk="$(bar "${disk_used/'.'*}" "${disk_total/'.'*}") $disk" ;; + "perc") disk="$disk_total_per $(bar "${disk_used/'.'*}" "${disk_total/'.'*}")" ;; esac } From d738ad6f823c25fec58cc07659adf846de9d8b29 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 16 Dec 2016 23:14:20 +1100 Subject: [PATCH 05/14] Disk: If df fails, abort --- neofetch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neofetch b/neofetch index 6e9af93e..1c019f13 100755 --- a/neofetch +++ b/neofetch @@ -1540,7 +1540,7 @@ get_disk() { type -p df >/dev/null 2>&1 || { err "Disk requires 'df' to function. Install 'df' to get disk info."; return; } # Get the info for / - disks=($(df -h /)) + disks=($(df -h /)) || { err "Disk: 'df' exited with error code 1"; return; } # Split the info disk_used="${disks[9]}" From 157911547a6177a85f174a3bd97b133770c53ff8 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 16 Dec 2016 23:47:08 +1100 Subject: [PATCH 06/14] Disk: Split the output differently for macOS --- neofetch | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/neofetch b/neofetch index 1c019f13..79c70b3e 100755 --- a/neofetch +++ b/neofetch @@ -1543,9 +1543,20 @@ get_disk() { disks=($(df -h /)) || { err "Disk: 'df' exited with error code 1"; return; } # Split the info - disk_used="${disks[9]}" - disk_total="${disks[8]}" - disk_total_per="(${disks[11]})" + case "$os" in + "Haiku") return ;; + "Mac OS X") + disk_used="${disks[10]}" + disk_total="${disks[9]}" + disk_total_per="(${disks[12]})" + ;; + + *) + disk_used="${disks[9]}" + disk_total="${disks[8]}" + disk_total_per="(${disks[11]})" + ;; + esac # Put it all together disk="${disk_used} / ${disk_total} ${disk_total_per}" From 43eaf34242ddecc74036f4af9e0ec3004607099b Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 16 Dec 2016 23:52:10 +1100 Subject: [PATCH 07/14] Disk: Test df output on travis --- neofetch | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/neofetch b/neofetch index 79c70b3e..9864ed15 100755 --- a/neofetch +++ b/neofetch @@ -22,6 +22,11 @@ shopt -s nocasematch # Reset colors/bold reset="\033[0m" +echo; echo +df -h +echo; echo +exit + # DETECT INFORMATION get_os() { @@ -1545,11 +1550,7 @@ get_disk() { # Split the info case "$os" in "Haiku") return ;; - "Mac OS X") - disk_used="${disks[10]}" - disk_total="${disks[9]}" - disk_total_per="(${disks[12]})" - ;; + "Mac OS X") ;; *) disk_used="${disks[9]}" From 265e14b1518770820d26c8a603de4764dc348971 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 16 Dec 2016 23:56:33 +1100 Subject: [PATCH 08/14] Disk: Remove test --- neofetch | 6 ------ 1 file changed, 6 deletions(-) diff --git a/neofetch b/neofetch index 9864ed15..a5a64400 100755 --- a/neofetch +++ b/neofetch @@ -22,11 +22,6 @@ shopt -s nocasematch # Reset colors/bold reset="\033[0m" -echo; echo -df -h -echo; echo -exit - # DETECT INFORMATION get_os() { @@ -1551,7 +1546,6 @@ get_disk() { case "$os" in "Haiku") return ;; "Mac OS X") ;; - *) disk_used="${disks[9]}" disk_total="${disks[8]}" From 868d8c2d8e85bb316e97d6904a4c3b8e9ae6ee31 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 17 Dec 2016 00:03:58 +1100 Subject: [PATCH 09/14] Disk: [macOS] Use -P --- neofetch | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/neofetch b/neofetch index a5a64400..1c89a8ab 100755 --- a/neofetch +++ b/neofetch @@ -1539,20 +1539,20 @@ get_term_font() { get_disk() { type -p df >/dev/null 2>&1 || { err "Disk requires 'df' to function. Install 'df' to get disk info."; return; } - # Get the info for / - disks=($(df -h /)) || { err "Disk: 'df' exited with error code 1"; return; } - # Split the info case "$os" in "Haiku") return ;; - "Mac OS X") ;; - *) - disk_used="${disks[9]}" - disk_total="${disks[8]}" - disk_total_per="(${disks[11]})" - ;; + "Mac OS X") df_flags=(-P -h /) ;; + *) df_flags=(-h /) ;; esac + # Get the info for / + disks=($(df "${df_flags[@]}")) || { err "Disk: 'df' exited with error code 1"; return; } + + disk_used="${disks[9]}" + disk_total="${disks[8]}" + disk_total_per="(${disks[11]})" + # Put it all together disk="${disk_used} / ${disk_total} ${disk_total_per}" From 91143de1a5619435492a8cfd1c953dd80d0d10d3 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 17 Dec 2016 00:06:12 +1100 Subject: [PATCH 10/14] Disk: Use -P for all OS --- neofetch | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/neofetch b/neofetch index 1c89a8ab..94e71769 100755 --- a/neofetch +++ b/neofetch @@ -1539,15 +1539,8 @@ get_term_font() { get_disk() { type -p df >/dev/null 2>&1 || { err "Disk requires 'df' to function. Install 'df' to get disk info."; return; } - # Split the info - case "$os" in - "Haiku") return ;; - "Mac OS X") df_flags=(-P -h /) ;; - *) df_flags=(-h /) ;; - esac - # Get the info for / - disks=($(df "${df_flags[@]}")) || { err "Disk: 'df' exited with error code 1"; return; } + disks=($(df -P -h /)) || { err "Disk: 'df' exited with error code 1"; return; } disk_used="${disks[9]}" disk_total="${disks[8]}" From 5d9901b34e3efde49eec0889db9748595332550a Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 17 Dec 2016 00:12:51 +1100 Subject: [PATCH 11/14] Disk: Ommit 'i' --- neofetch | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/neofetch b/neofetch index 94e71769..01a878b4 100755 --- a/neofetch +++ b/neofetch @@ -1542,8 +1542,8 @@ get_disk() { # Get the info for / disks=($(df -P -h /)) || { err "Disk: 'df' exited with error code 1"; return; } - disk_used="${disks[9]}" - disk_total="${disks[8]}" + disk_used="${disks[9]/i}" + disk_total="${disks[8]/i}" disk_total_per="(${disks[11]})" # Put it all together From b2e8c33c3d5e7d576eee613c36eba3346134520c Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 17 Dec 2016 00:25:58 +1100 Subject: [PATCH 12/14] Disk: Fix progress bars --- neofetch | 2 ++ 1 file changed, 2 insertions(+) diff --git a/neofetch b/neofetch index 01a878b4..5b83ae2d 100755 --- a/neofetch +++ b/neofetch @@ -1552,6 +1552,8 @@ get_disk() { # Convert Terabytes to Gigabytes. if [[ "$disk_display" != "off" ]]; then disk_used="${disk_used/\.}" + disk_used="${disk_used/G}" + disk_total="${disk_total/G}" disk_total="${disk_total/\.}" [[ "${disk_used: -1}" == "T" ]] && \ From 952834f8be6faa6cd4b4f97f78146f7f59598228 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 17 Dec 2016 10:11:51 +1100 Subject: [PATCH 13/14] Disk: Use usage percentage to calculate bar --- neofetch | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/neofetch b/neofetch index 5b83ae2d..7da79269 100755 --- a/neofetch +++ b/neofetch @@ -1538,6 +1538,7 @@ get_term_font() { get_disk() { type -p df >/dev/null 2>&1 || { err "Disk requires 'df' to function. Install 'df' to get disk info."; return; } + [[ "$os" == "Haiku" ]] && { err "Disk doesn't work on Haiku due to the non-standard 'df'"; return; } # Get the info for / disks=($(df -P -h /)) || { err "Disk: 'df' exited with error code 1"; return; } @@ -1549,26 +1550,12 @@ get_disk() { # Put it all together disk="${disk_used} / ${disk_total} ${disk_total_per}" - # Convert Terabytes to Gigabytes. - if [[ "$disk_display" != "off" ]]; then - disk_used="${disk_used/\.}" - disk_used="${disk_used/G}" - disk_total="${disk_total/G}" - disk_total="${disk_total/\.}" - - [[ "${disk_used: -1}" == "T" ]] && \ - disk_used="$((${disk_used/T} * 100))" - - [[ "${disk_total: -1}" == "T" ]] && \ - disk_total="$((${disk_total/T} * 100))" - fi - # Bar case "$disk_display" in - "bar") disk="$(bar "${disk_used/'.'*}" "${disk_total/'.'*}")" ;; - "infobar") disk+=" $(bar "${disk_used/'.'*}" "${disk_total/'.'*}")" ;; - "barinfo") disk="$(bar "${disk_used/'.'*}" "${disk_total/'.'*}") $disk" ;; - "perc") disk="$disk_total_per $(bar "${disk_used/'.'*}" "${disk_total/'.'*}")" ;; + "bar") disk="$(bar "${disk_total_per/'%'}" "100")" ;; + "infobar") disk+=" $(bar "${disk_total_per/'%'}" "100")" ;; + "barinfo") disk="$(bar "${disk_total_per/'%'}" "100") $disk" ;; + "perc") disk="$disk_total_per $(bar "$disk_total_per" "100")" ;; esac } From 7b99e15e1f2d4685cad9033f99b4752ab87d5f2e Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 17 Dec 2016 10:22:11 +1100 Subject: [PATCH 14/14] Disk: Don't declare variables if we're only using them once --- neofetch | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/neofetch b/neofetch index 7da79269..e38b6903 100755 --- a/neofetch +++ b/neofetch @@ -1543,19 +1543,16 @@ get_disk() { # Get the info for / disks=($(df -P -h /)) || { err "Disk: 'df' exited with error code 1"; return; } - disk_used="${disks[9]/i}" - disk_total="${disks[8]/i}" - disk_total_per="(${disks[11]})" - # Put it all together - disk="${disk_used} / ${disk_total} ${disk_total_per}" + disk_perc="${disks[11]/'%'}" + disk="${disks[9]/i} / ${disks[8]/i} (${disk_perc}%)" # Bar case "$disk_display" in - "bar") disk="$(bar "${disk_total_per/'%'}" "100")" ;; - "infobar") disk+=" $(bar "${disk_total_per/'%'}" "100")" ;; - "barinfo") disk="$(bar "${disk_total_per/'%'}" "100") $disk" ;; - "perc") disk="$disk_total_per $(bar "$disk_total_per" "100")" ;; + "bar") disk="$(bar "$disk_perc" "100")" ;; + "infobar") disk+=" $(bar "$disk_perc" "100")" ;; + "barinfo") disk="$(bar "$disk_perc" "100") $disk" ;; + "perc") disk="${disk_perc}% $(bar "$disk_perc" "100")" ;; esac }