disk: cleanup

This commit is contained in:
Dylan Araps 2018-06-01 09:29:51 +10:00
parent 226f746c60
commit f8779be333
1 changed files with 20 additions and 9 deletions

View File

@ -3053,15 +3053,17 @@ get_disk() {
type -p df >/dev/null 2>&1 ||\ type -p df >/dev/null 2>&1 ||\
{ err "Disk requires 'df' to function. Install 'df' to get disk info."; return; } { err "Disk requires 'df' to function. Install 'df' to get disk info."; return; }
# Get "df" version.
df_version="$(df --version 2>&1)" df_version="$(df --version 2>&1)"
case "$df_version" in case "$df_version" in
*"IMitv"*) df_flags=(-P -g) ;; # AIX
*"befhikm"*) df_flags=(-P -k) ;; # IRIX
*"Tracker"*) # Haiku *"Tracker"*) # Haiku
err "Your version of df cannot be used due to the non-standard flags" err "Your version of df cannot be used due to the non-standard flags"
return return
;; ;;
*"IMitv"*) df_flags=(-P -g) ;; # AIX
*"befhikm"*) df_flags=(-P -k) ;; # IRIX
*) df_flags=(-P -h) ;; *) df_flags=(-P -h) ;;
esac esac
@ -3071,10 +3073,10 @@ get_disk() {
unset "disks[0]" unset "disks[0]"
# Stop here if 'df' fails to print disk info. # Stop here if 'df' fails to print disk info.
if [[ -z "${disks[*]}" ]]; then [[ -z "${disks[*]}" ]] && {
err "Disk: df failed to print the disks, make sure the disk_show array is set properly." err "Disk: df failed to print the disks, make sure the disk_show array is set properly."
return return
fi }
for disk in "${disks[@]}"; do for disk in "${disks[@]}"; do
# Create a second array and make each element split at whitespace this time. # Create a second array and make each element split at whitespace this time.
@ -3085,17 +3087,26 @@ get_disk() {
*"befhikm"*) *"befhikm"*)
disk="$((disk_info[2]/1024/1024))G / $((disk_info[1]/1024/1024))G (${disk_perc}%)" disk="$((disk_info[2]/1024/1024))G / $((disk_info[1]/1024/1024))G (${disk_perc}%)"
;; ;;
*) disk="${disk_info[2]/i} / ${disk_info[1]/i} (${disk_perc}%)" ;;
*)
disk="${disk_info[2]/i} / ${disk_info[1]/i} (${disk_perc}%)"
;;
esac esac
# Subtitle. # Subtitle.
case "$disk_subtitle" in case "$disk_subtitle" in
"name") disk_sub="${disk_info[0]}" ;; "name")
disk_sub="${disk_info[0]}"
;;
"dir") "dir")
disk_sub="${disk_info[5]/*\/}" disk_sub="${disk_info[5]/*\/}"
[[ -z "$disk_sub" ]] && disk_sub="${disk_info[5]}" disk_sub="${disk_sub:-${disk_info[5]}}"
;;
*)
disk_sub="${disk_info[5]}"
;; ;;
*) disk_sub="${disk_info[5]}" ;;
esac esac
# Bar. # Bar.