From aed21c449c268b336bbf67ee4a0c1d22824cb2bf Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 6 Jan 2017 18:50:05 +1100 Subject: [PATCH 01/12] Config: Added disk_show --- config/config | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/config/config b/config/config index 28381d30..1056132e 100644 --- a/config/config +++ b/config/config @@ -32,7 +32,7 @@ print_info() { info "Memory" memory # info "CPU Usage" cpu_usage - # info "Disk (root)" disk + # info "Disk" disk # info "Battery" battery # info "Font" font # info "Song" song @@ -230,6 +230,7 @@ gpu_brand="on" # GPU1: Intel Integrated Graphics gpu_type="all" + # Resolution @@ -294,6 +295,28 @@ gtk3="on" public_ip_host="http://ident.me" +# Disk + + +# Which disks to display. +# The values can be any /dev/sdx, mount point or directory. +# NOTE: By default we only show the disk info for '/'. +# +# Default: '/' +# Values: '/', '/dev/sdx', '/path/to/drive'. +# Flag: --disk_show +# +# Example: +# disk_show=('/' '/dev/sdb1'): +# 'Disk (/): 74G / 118G (66%)' +# 'Disk (/mnt/Videos): 823G / 893G (93%)' +# +# disk_show=('/'): +# 'Disk (/): 74G / 118G (66%)' +# +disk_show=('/') + + # Song From 5b1f273dfc2d0cb43ce94eb056a7584f6e5b54c9 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 6 Jan 2017 18:53:26 +1100 Subject: [PATCH 02/12] Disk: Add disk_show --- neofetch | 51 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/neofetch b/neofetch index 0dd96f3c..49e2b12b 100755 --- a/neofetch +++ b/neofetch @@ -1622,20 +1622,32 @@ get_disk() { *) df_flags=(-P -h) ;; esac - # Get the info for "/". - disks=($(df "${df_flags[@]}" /)) || { err "Disk: 'df' exited with error code 1"; return; } + # Create an array called 'disks' where each element is a separate line from + # df's output. We then unset the first element which removes the column titles. + readarray disks < <(df "${df_flags[@]}" "${disk_show[@]:-/}") && unset 'disks[0]' - # Put it all together. - disk_perc="${disks[11]/'%'}" - disk="${disks[9]/i} / ${disks[8]/i} (${disk_perc}%)" + # Stop here if 'df' fails to print disk info. + [[ -z "${disks[@]}" ]] && \ + { err "Disk: df failed to print the disks, make sure the disk_show array is set properly."; return; } - # Bar. - case "$disk_display" in - "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 + for disk in "${disks[@]}"; do + # Create a second array and make each element split at whitespacw this time. + disk_info=($disk) + disk_perc="${disk_info[4]/'%'}" + + disk="${disk_info[2]/i} / ${disk_info[1]/i} (${disk_perc}%)" + + # Bar. + case "$disk_display" in + "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 + + # Append '(disk mount point)' to the subtitle. + prin "${subtitle} (${disk_info[5]})" "$disk" + done } get_battery() { @@ -3531,6 +3543,10 @@ INFO: --gtk3 on/off Enable/Disable gtk3 theme/font/icons output --shell_path on/off Enable/Disable showing \$SHELL path --shell_version on/off Enable/Disable showing \$SHELL version + --disk_show value Which disks to display. + Takes: '/', '/dev/sdXX', '/path/to/mount point' + + NOTE: Multiple values can be given. (--disk_show '/' '/dev/sdc1') --ip_host url URL to query for public IP --song_shorthand on/off Print the Artist/Title on separate lines --install_time on/off Enable/Disable showing the time in Install Date output. @@ -3695,6 +3711,17 @@ get_args() { [[ "$cpu_temp" == "on" ]] && cpu_temp="C" ;; + "--disk_show") + unset disk_show + for arg in "$@"; do + case "$arg" in + "--disk_show") ;; + "-"*) break ;; + *) disk_show+=($arg) + esac + done + ;; + "--disable") for func in "$@"; do case "$func" in From e2d7bacb4f835d75002e827f28401a12a6ab3004 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 6 Jan 2017 18:53:40 +1100 Subject: [PATCH 03/12] Docs: Add disk_show --- neofetch.1 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/neofetch.1 b/neofetch.1 index 7beca468..5e6fbd36 100644 --- a/neofetch.1 +++ b/neofetch.1 @@ -90,6 +90,12 @@ Enable/Disable showing $SHELL path \fB\-\-shell_version\fR on/off Enable/Disable showing $SHELL version .TP +\fB\-\-disk_show\fR value +Which disks to display. +Takes: '/', '/dev/sdXX', '/path/to/mount point' +.IP +NOTE: Multiple values can be given. (\fB\-\-disk_show\fR '/' '/dev/sdc1') +.TP \fB\-\-ip_host\fR url URL to query for public IP .TP From 886a51db120a906f0eca3338cdbd20f291a4eeeb Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 6 Jan 2017 19:01:48 +1100 Subject: [PATCH 04/12] Docs: Fix comment --- config/config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/config b/config/config index 1056132e..979bc0c0 100644 --- a/config/config +++ b/config/config @@ -299,11 +299,11 @@ public_ip_host="http://ident.me" # Which disks to display. -# The values can be any /dev/sdx, mount point or directory. +# The values can be any /dev/sdXX, mount point or directory. # NOTE: By default we only show the disk info for '/'. # # Default: '/' -# Values: '/', '/dev/sdx', '/path/to/drive'. +# Values: '/', '/dev/sdXX', '/path/to/drive'. # Flag: --disk_show # # Example: From 9b21e73276474d78c0e282f3bb354706560555e1 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 6 Jan 2017 19:03:14 +1100 Subject: [PATCH 05/12] Disk: Fix typo --- neofetch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neofetch b/neofetch index 49e2b12b..9db4c037 100755 --- a/neofetch +++ b/neofetch @@ -1631,7 +1631,7 @@ get_disk() { { err "Disk: df failed to print the disks, make sure the disk_show array is set properly."; return; } for disk in "${disks[@]}"; do - # Create a second array and make each element split at whitespacw this time. + # Create a second array and make each element split at whitespace this time. disk_info=($disk) disk_perc="${disk_info[4]/'%'}" From 6c26589670e976011b4a0e97b9c1465e25771fed Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 6 Jan 2017 19:28:50 +1100 Subject: [PATCH 06/12] Disk: Remove -P from flags --- neofetch | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/neofetch b/neofetch index 9db4c037..9de18241 100755 --- a/neofetch +++ b/neofetch @@ -1618,8 +1618,8 @@ get_disk() { # Get "df" flags. case "$os" in "Haiku") err "Disk doesn't work on Haiku due to the non-standard 'df'"; return ;; - "Minix") df_flags=(-h) ;; - *) df_flags=(-P -h) ;; + "Mac OS X") df_flags=(-P -h) ;; + *) df_flags=(-h) ;; esac # Create an array called 'disks' where each element is a separate line from From c1b320de32063c5b7e13effa114128c9deffbe54 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 6 Jan 2017 21:23:51 +1100 Subject: [PATCH 07/12] Disk: Use -h for all OS but Haiku --- neofetch | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/neofetch b/neofetch index 9de18241..cef5b50f 100755 --- a/neofetch +++ b/neofetch @@ -1614,17 +1614,11 @@ 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 "df" flags. - case "$os" in - "Haiku") err "Disk doesn't work on Haiku due to the non-standard 'df'"; return ;; - "Mac OS X") df_flags=(-P -h) ;; - *) df_flags=(-h) ;; - esac + [[ "$os" == "Haiku" ]] && { err "Disk doesn't work on Haiku due to the non-standard 'df'"; return; } # Create an array called 'disks' where each element is a separate line from # df's output. We then unset the first element which removes the column titles. - readarray disks < <(df "${df_flags[@]}" "${disk_show[@]:-/}") && unset 'disks[0]' + readarray disks < <(df -h "${disk_show[@]:-/}") && unset 'disks[0]' # Stop here if 'df' fails to print disk info. [[ -z "${disks[@]}" ]] && \ From adfce4efbddf67ebbfe4bfd70ce15d8e5bef4d82 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 6 Jan 2017 21:29:35 +1100 Subject: [PATCH 08/12] Travis: Added a temporary test for travis --- neofetch | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/neofetch b/neofetch index cef5b50f..5becab4d 100755 --- a/neofetch +++ b/neofetch @@ -1642,6 +1642,10 @@ get_disk() { # Append '(disk mount point)' to the subtitle. prin "${subtitle} (${disk_info[5]})" "$disk" done + + # Temporary test for mac OS. + df -h "${disk_show[@]:-/}" + exit } get_battery() { From 50bd2eb9d7e0e6568835e91fa5081118ebd8d51a Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 6 Jan 2017 21:34:25 +1100 Subject: [PATCH 09/12] Travis: Modify test --- neofetch | 1 + 1 file changed, 1 insertion(+) diff --git a/neofetch b/neofetch index 5becab4d..09106151 100755 --- a/neofetch +++ b/neofetch @@ -1645,6 +1645,7 @@ get_disk() { # Temporary test for mac OS. df -h "${disk_show[@]:-/}" + df -h / exit } From 2404a5e0adfe5a39cac70d01eb9db27c45c98161 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 6 Jan 2017 21:39:50 +1100 Subject: [PATCH 10/12] Disk: Revert previous commits --- neofetch | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/neofetch b/neofetch index 09106151..9de18241 100755 --- a/neofetch +++ b/neofetch @@ -1614,11 +1614,17 @@ 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 "df" flags. + case "$os" in + "Haiku") err "Disk doesn't work on Haiku due to the non-standard 'df'"; return ;; + "Mac OS X") df_flags=(-P -h) ;; + *) df_flags=(-h) ;; + esac # Create an array called 'disks' where each element is a separate line from # df's output. We then unset the first element which removes the column titles. - readarray disks < <(df -h "${disk_show[@]:-/}") && unset 'disks[0]' + readarray disks < <(df "${df_flags[@]}" "${disk_show[@]:-/}") && unset 'disks[0]' # Stop here if 'df' fails to print disk info. [[ -z "${disks[@]}" ]] && \ @@ -1642,11 +1648,6 @@ get_disk() { # Append '(disk mount point)' to the subtitle. prin "${subtitle} (${disk_info[5]})" "$disk" done - - # Temporary test for mac OS. - df -h "${disk_show[@]:-/}" - df -h / - exit } get_battery() { From 1241f839f7719cb62669a1658a90ab910eff5ad8 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sun, 8 Jan 2017 12:26:59 +1100 Subject: [PATCH 11/12] General: Remove readarray usage --- neofetch | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/neofetch b/neofetch index 9de18241..72d57bd2 100755 --- a/neofetch +++ b/neofetch @@ -11,6 +11,7 @@ bash_version="${BASH_VERSION/.*}" sys_locale="${LANG:-C}" XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-${HOME}/.config}" +old_ifs="$IFS" # Speed up script by not using unicode. export LC_ALL=C @@ -993,7 +994,9 @@ get_gpu() { case "$os" in "Linux") # Read GPUs into array. - readarray gpus < <(lspci -mm | awk -F '\\"|\\" \\"' '/"Display|"3D|"VGA/ {print $3 " " $4}') + IFS=$'\n' + gpus=($(lspci -mm | awk -F '\\"|\\" \\"' '/"Display|"3D|"VGA/ {print $3 " " $4}')) + IFS="$old_ifs" # Number the GPUs if more than one exists. ((${#gpus[@]} > 1)) && gpu_num=1 @@ -1624,7 +1627,9 @@ get_disk() { # Create an array called 'disks' where each element is a separate line from # df's output. We then unset the first element which removes the column titles. - readarray disks < <(df "${df_flags[@]}" "${disk_show[@]:-/}") && unset 'disks[0]' + IFS=$'\n' + disks=($(df "${df_flags[@]}" "${disk_show[@]:-/}")) && unset 'disks[0]' + IFS="$old_ifs" # Stop here if 'df' fails to print disk info. [[ -z "${disks[@]}" ]] && \ From 2e69b7f64c981d59fc18e43e9fcbbd1fc2928231 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sun, 8 Jan 2017 14:23:55 +1100 Subject: [PATCH 12/12] Disk: Added --disk_subtitle --- config/config | 15 +++++++++++++++ neofetch | 16 +++++++++++++++- neofetch.1 | 7 +++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/config/config b/config/config index 979bc0c0..7fe75e6d 100644 --- a/config/config +++ b/config/config @@ -316,6 +316,21 @@ public_ip_host="http://ident.me" # disk_show=('/') +# Disk subtitle. +# What to append to the Disk subtitle. +# +# Default: 'mount' +# Values: 'mount', 'name' +# Flag: --disk_subtitle +# +# Example: +# name: 'Disk (/dev/sda1): 74G / 118G (66%)' +# 'Disk (/dev/sdb2): 74G / 118G (66%)' +# +# mount: 'Disk (/): 74G / 118G (66%)' +# 'Disk (/mnt/Local Disk): 74G / 118G (66%)' +disk_subtitle="mount" + # Song diff --git a/neofetch b/neofetch index 72d57bd2..f108a626 100755 --- a/neofetch +++ b/neofetch @@ -1642,6 +1642,12 @@ get_disk() { disk="${disk_info[2]/i} / ${disk_info[1]/i} (${disk_perc}%)" + # Subtitle + case "$disk_subtitle" in + "name") disk_sub="${disk_info[0]}" ;; + *) disk_sub="${disk_info[5]}" ;; + esac + # Bar. case "$disk_display" in "bar") disk="$(bar "$disk_perc" "100")" ;; @@ -1651,7 +1657,7 @@ get_disk() { esac # Append '(disk mount point)' to the subtitle. - prin "${subtitle} (${disk_info[5]})" "$disk" + prin "${subtitle} (${disk_sub})" "$disk" done } @@ -3552,6 +3558,13 @@ INFO: Takes: '/', '/dev/sdXX', '/path/to/mount point' NOTE: Multiple values can be given. (--disk_show '/' '/dev/sdc1') + + --disk_subtitle name/mount What information to append to the Disk subtitle. + + 'name' shows the disk's name (sda1, sda2, etc) + + 'mount' shows the disk's mount point (/, /mnt/Local Disk, etc) + --ip_host url URL to query for public IP --song_shorthand on/off Print the Artist/Title on separate lines --install_time on/off Enable/Disable showing the time in Install Date output. @@ -3716,6 +3729,7 @@ get_args() { [[ "$cpu_temp" == "on" ]] && cpu_temp="C" ;; + "--disk_subtitle") disk_subtitle="$2" ;; "--disk_show") unset disk_show for arg in "$@"; do diff --git a/neofetch.1 b/neofetch.1 index 5e6fbd36..d2fbdc5f 100644 --- a/neofetch.1 +++ b/neofetch.1 @@ -96,6 +96,13 @@ Takes: '/', '/dev/sdXX', '/path/to/mount point' .IP NOTE: Multiple values can be given. (\fB\-\-disk_show\fR '/' '/dev/sdc1') .TP +\fB\-\-disk_subtitle\fR name/mount +What information to append to the Disk subtitle. +.IP +\&'name' shows the disk's name (sda1, sda2, etc) +.IP +\&'mount' shows the disk's mount point (/, \fI\,/mnt/Local\/\fP Disk, etc) +.TP \fB\-\-ip_host\fR url URL to query for public IP .TP