General: Function cleanup

This commit is contained in:
Dylan Araps 2016-11-06 17:08:09 +11:00
parent ba0c7e441f
commit 5288a609e5
1 changed files with 32 additions and 60 deletions

View File

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