From 77261333338770ceed2a12017f75d81bb57674fa Mon Sep 17 00:00:00 2001 From: Muhammad Herdiansyah Date: Sun, 18 Dec 2016 11:31:11 +0700 Subject: [PATCH 1/5] OS: Merged Linux and BSD distro detection --- neofetch | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/neofetch b/neofetch index 05b17e28..cccaf7a5 100755 --- a/neofetch +++ b/neofetch @@ -53,8 +53,8 @@ get_distro() { [[ "$distro" ]] && return case "$os" in - "Linux") - if [[ "$(< /proc/version)" == *"Microsoft"* || "$(< /proc/sys/kernel/osrelease)" == *"Microsoft"* ]]; then + "Linux" | "BSD" | "MINIX") + if [[ "$(< /proc/version)" == *"Microsoft"* || "$(< /proc/sys/kernel/osrelease)" == *"Microsoft"* ]]; then ## ERRORS NEED TO BE SUPPRESSED! case "$distro_shorthand" in "on") distro="$(lsb_release -sir) [Windows 10]" ;; "tiny") distro="Windows 10" ;; @@ -95,9 +95,9 @@ get_distro() { elif [[ -d "/system/app/" && -d "/system/priv-app" ]]; then distro="Android $(getprop ro.build.version.release)" - else - # Source the os-release file. - for file in /etc/os-release /usr/lib/os-release /etc/*release /usr/lib/*release; do + elif [[ -f "/etc/os-release" || -f "/usr/lib/os-release" ]]; then + # Source the os-release file + for file in /etc/os-release /usr/lib/os-release; do source "$file" 2>/dev/null && break done @@ -111,6 +111,21 @@ get_distro() { # Workarounds for distros that go against the os-release standard. [[ -z "${distro// }" ]] && distro="$(awk '/BLAG/ {print $1; exit}' /etc/*ease /usr/lib/*ease)" [[ -z "${distro// }" ]] && distro="$(awk -F'=' '{print $2; exit}' /etc/*ease /usr/lib/*ease)" + + else + distro="$(cat /etc/*-release)" # UUOC, but using usual bash $(< *-file) returns "ambiguous redirect" + if [[ -z "$distro" ]]; then + case "$distro_shorthand" in + "on" | "tiny") distro="$kernel_name" ;; + *) distro="$kernel_name $kernel_version" ;; + esac + distro="${distro/DragonFly/DragonFlyBSD}" + + # Workarounds for FreeBSD based distros. + [[ -f "/etc/pcbsd-lang" ]] && distro="PCBSD" + [[ -f "/etc/rc.conf.trueos" ]] && distro="TrueOS" + [[ -f "/etc/pacbsd-release" ]] && distro="PacBSD" # /etc/pacbsd-release is an empty file + fi fi distro="$(trim_quotes "$distro")" ;; @@ -153,20 +168,6 @@ get_distro() { os_arch="off" ;; - "BSD" | "MINIX") - case "$distro_shorthand" in - "tiny" | "on") distro="$kernel_name" ;; - *) distro="$kernel_name $kernel_version" ;; - esac - - distro="${distro/DragonFly/DragonFlyBSD}" - - # Workarounds for FreeBSD based distros. - [[ -f "/etc/pcbsd-lang" ]] && distro="PCBSD" - [[ -f "/etc/trueos-lang" ]] && distro="TrueOS" - [[ -f "/etc/pacbsd-release" ]] && distro="PacBSD" - ;; - "Windows") distro="$(wmic os get Caption /value)" From 5f48a04bda43c357717018712769e959868bd1d3 Mon Sep 17 00:00:00 2001 From: Muhammad Herdiansyah Date: Sun, 18 Dec 2016 11:33:24 +0700 Subject: [PATCH 2/5] Packages: Merged Linux and BSD package detection --- neofetch | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/neofetch b/neofetch index cccaf7a5..3d7ff3a2 100755 --- a/neofetch +++ b/neofetch @@ -394,7 +394,7 @@ get_packages() { local PATH="${PATH#:}" case "$os" in - "Linux" | "iPhone OS" | "Solaris") + "Linux" | "BSD" | "iPhone OS" | "Solaris") type -p pacman >/dev/null && \ packages="$(pacman -Qq --color never | wc -l)" @@ -446,8 +446,12 @@ get_packages() { type -p eopkg >/dev/null && \ packages="$((packages+=$(eopkg list-installed | wc -l)))" + type -p pkg_info >/dev/null && \ + packages="$((packages+=$(pkg_info | wc -l)))" + if type -p pkg >/dev/null; then packages="$((packages+=$(ls -1 /var/db/pkg | wc -l)))" + (("$packages" == "0")) && packages="$((packages+=$(pkg info | wc -l)))" (("$packages" == "0")) && packages="$((packages+=$(pkg list | wc -l)))" fi ;; @@ -466,21 +470,6 @@ get_packages() { packages="$((packages + $(pkgin list | wc -l)))" ;; - "BSD") - case "$distro" in - # PacBSD has both pacman and pkg, but only pacman is used. - "PacBSD"*) packages="$(pacman -Qq --color never | wc -l)" ;; - - *) - if type -p pkg_info >/dev/null; then - packages="$(pkg_info | wc -l)" - elif type -p pkg >/dev/null; then - packages="$(pkg info | wc -l)" - fi - ;; - esac - ;; - "Windows") packages="$(cygcheck -cd | wc -l)" From 2bad735fb3092d5634a0c1225e6489c85e7c98d7 Mon Sep 17 00:00:00 2001 From: Muhammad Herdiansyah Date: Sun, 18 Dec 2016 11:52:09 +0700 Subject: [PATCH 3/5] Packages: Separate FreeBSD pkg from Linux/Solaris pkg detection --- neofetch | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/neofetch b/neofetch index 3d7ff3a2..3c382581 100755 --- a/neofetch +++ b/neofetch @@ -450,9 +450,12 @@ get_packages() { packages="$((packages+=$(pkg_info | wc -l)))" if type -p pkg >/dev/null; then - packages="$((packages+=$(ls -1 /var/db/pkg | wc -l)))" - (("$packages" == "0")) && packages="$((packages+=$(pkg info | wc -l)))" - (("$packages" == "0")) && packages="$((packages+=$(pkg list | wc -l)))" + case "$kernel_name" in + "FreeBSD") packages="$((packages+=$(pkg info | wc -l)))" ;; + *) + packages="$((packages+=$(ls -1 /var/db/pkg | wc -l)))" + (("$packages" == "0")) && packages="$((packages+=$(pkg list | wc -l)))" + esac fi ;; From e4d7baecaf4f055d4049fffe37436f847d06bdaf Mon Sep 17 00:00:00 2001 From: Muhammad Herdiansyah Date: Wed, 28 Dec 2016 09:03:58 +0700 Subject: [PATCH 4/5] Distro: Apply suggestion --- neofetch | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/neofetch b/neofetch index 3c382581..50402371 100755 --- a/neofetch +++ b/neofetch @@ -54,7 +54,7 @@ get_distro() { case "$os" in "Linux" | "BSD" | "MINIX") - if [[ "$(< /proc/version)" == *"Microsoft"* || "$(< /proc/sys/kernel/osrelease)" == *"Microsoft"* ]]; then ## ERRORS NEED TO BE SUPPRESSED! + if [[ "$(< /proc/version)" == *"Microsoft"* || "$(< /proc/sys/kernel/osrelease)" == *"Microsoft"* ]]; then case "$distro_shorthand" in "on") distro="$(lsb_release -sir) [Windows 10]" ;; "tiny") distro="Windows 10" ;; @@ -109,11 +109,13 @@ get_distro() { esac # Workarounds for distros that go against the os-release standard. - [[ -z "${distro// }" ]] && distro="$(awk '/BLAG/ {print $1; exit}' /etc/*ease /usr/lib/*ease)" - [[ -z "${distro// }" ]] && distro="$(awk -F'=' '{print $2; exit}' /etc/*ease /usr/lib/*ease)" + [[ -z "${distro// }" ]] && distro="$(awk '/BLAG/ {print $1; exit}' /etc/os-release /usr/lib/os-release)" + [[ -z "${distro// }" ]] && distro="$(awk -F'=' '{print $2; exit}' /etc/os-release /usr/lib/os-release)" else - distro="$(cat /etc/*-release)" # UUOC, but using usual bash $(< *-file) returns "ambiguous redirect" + for release_file in /etc/*-release; do + distro+="$(< "$release_file")" + done if [[ -z "$distro" ]]; then case "$distro_shorthand" in "on" | "tiny") distro="$kernel_name" ;; From e7b90d08649757577bcf7425df3ce3ed90bb9ec0 Mon Sep 17 00:00:00 2001 From: Muhammad Herdiansyah Date: Wed, 28 Dec 2016 10:15:06 +0700 Subject: [PATCH 5/5] Distro: Suppressed errors --- neofetch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neofetch b/neofetch index 50402371..a4b49fbe 100755 --- a/neofetch +++ b/neofetch @@ -3472,7 +3472,7 @@ main() { get_os get_default_config 2>/dev/null get_args "$@" - get_distro + get_distro 2>/dev/null get_bold get_distro_colors