From 77261333338770ceed2a12017f75d81bb57674fa Mon Sep 17 00:00:00 2001 From: Muhammad Herdiansyah Date: Sun, 18 Dec 2016 11:31:11 +0700 Subject: [PATCH] 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)"