From 5288a609e5a659a5d918386097ad388578252c1a Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sun, 6 Nov 2016 17:08:09 +1100 Subject: [PATCH] General: Function cleanup --- neofetch | 92 ++++++++++++++++++++------------------------------------ 1 file changed, 32 insertions(+), 60 deletions(-) diff --git a/neofetch b/neofetch index 8bf9d03f..87d2fdee 100755 --- a/neofetch +++ b/neofetch @@ -229,10 +229,8 @@ getdistro() { distro="${distro/DragonFly/DragonFlyBSD}" - # Workaround for PCBSD as uname still displays FreeBSD. + # Workarounds for FreeBSD based distros. [ -f "/etc/pcbsd-lang" ] && distro="PCBSD" - - # Workaround for PacBSD as uname displays FreeBSD. [ -f "/etc/pacbsd-release" ] && distro="PacBSD" ;; @@ -279,25 +277,19 @@ gettitle() { getkernel() { case "$kernel_shorthand" in - "on") kernel_flags="-r" ;; - "off") kernel_flags="-sr" ;; + "on") kernel_flags="-r" ;; + "off") kernel_flags="-sr" ;; esac # Hardcode kernel settings in BSDs - case "$os" in - "BSD") - case "$distro" in - "PacBSD"* | "PCBSD"*) kernel="$(uname $kernel_flags)" ;; - *) - case "$distro_shorthand" in - "on" | "tiny") kernel=$(uname -r) ;; - *) unset kernel ;; - esac - ;; - esac - ;; - *) kernel="$(uname $kernel_flags)" ;; - esac + if [ "$os" == "BSD" ] && [[ ! "$distro" =~ (PacBSD|PCBSD) ]]; then + case "$distro_shorthand" in + "on" | "tiny") kernel=$(uname -r) ;; + *) unset kernel ;; + esac + else + kernel="$(uname $kernel_flags)" + fi } # }}} @@ -305,7 +297,6 @@ getkernel() { # Uptime {{{ getuptime() { - # Since Haiku's uptime cannot be fetched in seconds, a case outside # the usual case is needed case "$os" in @@ -496,30 +487,31 @@ getshell() { if [ "$shell_version" == "on" ]; then shell+=" " - case "$shell" in - *"bash"*) - shell+="$(bash --version | head -n 1)" + case "${SHELL##*/}" in + "bash") + shell+="$(bash --version)" shell="${shell/ *, version}" + shell="${shell/$'\n'*}" ;; - *"zsh"*) + "zsh") shell+="$(zsh --version)" shell="${shell/ zsh}" ;; - *"mksh"* | *"ksh") + "mksh" | "ksh") shell+="$("$SHELL" -c 'printf "%s" "$KSH_VERSION"')" shell="${shell/ * KSH}" ;; - *"tcsh"* | *"csh"*) + "tcsh" | "csh") shell+="$("$SHELL" --version)" shell="${shell/tcsh}" shell="${shell/\(*}" ;; - *"fish"*) - shell+="$("$SHELL" -c 'printf "%s" "$FISH_VERSION"')" + "fish") + shell+="$(fish -c 'printf "%s" "$FISH_VERSION"')" ;; esac shell="${shell/\(*\)}" @@ -767,15 +759,6 @@ getcpu() { "logical" | "on") cores="$(grep -c ^processor /proc/cpuinfo)" ;; "physical") cores="$(grep "^core id" /proc/cpuinfo | sort -u | wc -l)" ;; esac - - # Fix for speeds under 1ghz - if [ -z "${speed:1}" ]; then - speed="0.${speed}" - else - speed="${speed:0:1}.${speed:1}" - fi - - cpu="$cpu @ ${speed}GHz $temp" ;; "Mac OS X") @@ -828,15 +811,6 @@ getcpu() { # Get cpu cores cores="$(sysctl -n hw.ncpu)" - - # Fix for speeds under 1ghz - if [ -z "${speed:1}" ]; then - speed="0.${speed}" - else - speed="${speed:0:1}.${speed:1}" - fi - - cpu="$cpu @ ${speed}GHz" ;; "Solaris") @@ -854,15 +828,6 @@ getcpu() { "logical" | "on") cores="$(kstat -m cpu_info | grep -c "chip_id")" ;; "physical") cores="$(psrinfo -p)" ;; esac - - # Fix for speeds under 1ghz - if [ -z "${speed:1}" ]; then - speed="0.${speed}" - else - speed="${speed:0:1}.${speed:1}" - fi - - cpu="$cpu @ ${speed}GHz" ;; "Haiku") @@ -872,15 +837,21 @@ getcpu() { speed="${speed/MHz}" speed="$((speed / 100))" cores="$(sysinfo -cpu | grep -c 'CPU #')" + ;; + esac - # Fix for speed under 1ghz - if [ -z ] "${speed:1}"; then + # Format the output + case "$os" in + "Mac OS X" | "iPhone OS") ;; + *) + # Fix for speeds under 1ghz + if [ -z "${speed:1}" ]; then speed="0.${speed}" else speed="${speed:0:1}.${speed:1}" fi - cpu="$cpu @ ${speed}GHz" + cpu="$cpu @ ${speed}GHz $temp" ;; esac @@ -892,10 +863,11 @@ getcpu() { cpu="${cpu//(R)}" cpu="${cpu//CPU}" cpu="${cpu//Processor}" - cpu="${cpu//Six-Core}" - cpu="${cpu//Eight-Core}" + cpu="${cpu//Core}" cpu="${cpu//Dual-Core}" cpu="${cpu//Quad-Core}" + cpu="${cpu//Six-Core}" + cpu="${cpu//Eight-Core}" cpu="${cpu//with Radeon HD Graphics}" # Add cpu cores to output