Add FreeBSD-native handling

This commit is contained in:
Justin Coffman 2019-11-14 15:18:58 -05:00
commit 99533535f8
5 changed files with 46 additions and 7 deletions

View file

@ -99,6 +99,19 @@ __battery() {
;;
esac
done
elif [ $(uname -s) = 'FreeBSD' ]; then
bat_state=$(sysctl -n hw.acpi.battery.state)
if [ "$?" -eq 0 ]; then
full=100
rem=$(sysctl -n hw.acpi.battery.life)
if [ "$bat_state" -eq 1 ]; then
state="discharging"
elif [ "$bat_state" -eq 2 ]; then
state="charging"
else
state="unknown"
fi
fi
fi
if [ $rem -ge 0 ] && [ $full -gt 0 ]; then
percent=$(((100*$rem)/$full))

View file

@ -20,12 +20,20 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
__cpu_count_detail() {
if [ $(uname -s) = 'Linux' ]; then
grep -i "^model name" /proc/cpuinfo
elif [ $(uname -s) = 'FreeBSD' ]; then
sysctl -n hw.model | gsed 's/\s\+/ /g'
fi
}
__cpu_count() {
local c
if [ $(uname -s) = 'Linux' ]; then
c=$(getconf _NPROCESSORS_ONLN 2>/dev/null || grep -ci "^processor" /proc/cpuinfo)
elif [ $(uname -s) = 'FreeBSD' ]; then
c=$(sysctl -n hw.ncpu)
fi
[ "$c" = "1" ] || printf "%sx" "$c"
}

View file

@ -30,14 +30,28 @@ __cpu_freq() {
fpdiv $hz "1000000" 1 # 1Ghz
freq="$_RET"
elif [ -r "/proc/cpuinfo" ]; then
if egrep -q -s -i -m 1 "^cpu MHz|^clock" /proc/cpuinfo; then
freq=$(egrep -i -m 1 "^cpu MHz|^clock" /proc/cpuinfo | awk -F"[:.]" '{ printf "%01.1f", $2 / 1000 }')
if egrep -q -s -i -m 1 "^cpu MHz|^clock" /compat/linux/proc/cpuinfo; then
freq=$(egrep -i -m 1 "^cpu MHz|^clock" /compat/linux/proc/cpuinfo | awk -F"[:.]" '{ printf "%01.1f", $2 / 1000 }')
else
# Must scale frequency by number of processors, if counting bogomips
count=$(getconf _NPROCESSORS_ONLN 2>/dev/null || grep -ci "^processor" /proc/cpuinfo)
freq=$(egrep -i -m 1 "^bogomips" /proc/cpuinfo | awk -F"[:.]" '{ print $2 }')
count=$(getconf _NPROCESSORS_ONLN 2>/dev/null || grep -ci "^processor" /compat/linux/proc/cpuinfo)
freq=$(egrep -i -m 1 "^bogomips" /compat/linux/proc/cpuinfo | awk -F"[:.]" '{ print $2 }')
freq=$(printf "%s %s" "$freq" "$count" | awk '{printf "%01.1f\n", $1/$2/1000}')
fi
elif [ $(uname -s) = 'FreeBSD' ]; then
# Unless powerd running, this sysctl variable is unavailable.
# powerd may also not function in VMs, making this unusable.
hz=$(sysctl -in dev.cpu.0.freq)
if [ ! -z $hz ]; then
fpdiv $hz "1000" 1 # 1GHz
freq="$_RET"
if [ $(sysctl -n hw.model) =~ 'GHz' ]; then
freq=$(sysctl -n hw.model | gsed -e 's/.* //' -e 's/\([0-9]\)0[A-Za-z]\+/\1/')
elif [ $(sysctl -n hw.model) =~ 'MHz' ]; then
hz=$(sysctl -n hw.model | gsed -e 's/.* //' -e 's/[A-Za-z]\+$//')
fpdiv $hz "1000" 1
freq="$_RET"
fi
elif hz=$(sysctl -n hw.cpufrequency 2>/dev/null); then
fpdiv $hz "1000000000" 1 # 1Ghz
freq="$_RET"

View file

@ -83,6 +83,10 @@ __logo() {
logo="<@>"
$MARKUP && printf "$(color b W g)%s$(color -)" "$logo" || printf "$logo"
;;
*freebsd*)
logo="^O^"
$MARKUP && printf "$(color R k b)%s$(color -)" "$logo" || printf "$logo"
;;
*gentoo*)
logo=" > "
$MARKUP && printf "$(color b c w)%s$(color -)" "$logo" || printf "$logo"

View file

@ -36,7 +36,7 @@ __memory() {
esac
[ -n "${free}" -a -n "${total}" -a -n "${buffers}" -a -n "${cached}" ] && break;
done < /proc/meminfo
elif [ $(uname) = 'FreeBSD' ]; then
elif [ $(uname -s) = 'FreeBSD' ]; then
# FreeBSD support
# Adapted from https://www.cyberciti.biz/files/scripts/freebsd-memory.pl.txt
# Copyright (c) 2003-2004 Ralf S. Engelschall <rse@engelschall.com>