mirror of
https://github.com/dustinkirkland/byobu
synced 2025-08-21 22:13:19 -07:00
Add FreeBSD-native handling
This commit is contained in:
parent
87e7add159
commit
99533535f8
5 changed files with 46 additions and 7 deletions
|
@ -99,6 +99,19 @@ __battery() {
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
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
|
fi
|
||||||
if [ $rem -ge 0 ] && [ $full -gt 0 ]; then
|
if [ $rem -ge 0 ] && [ $full -gt 0 ]; then
|
||||||
percent=$(((100*$rem)/$full))
|
percent=$(((100*$rem)/$full))
|
||||||
|
|
|
@ -20,12 +20,20 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
__cpu_count_detail() {
|
__cpu_count_detail() {
|
||||||
grep -i "^model name" /proc/cpuinfo
|
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() {
|
__cpu_count() {
|
||||||
local c
|
local c
|
||||||
c=$(getconf _NPROCESSORS_ONLN 2>/dev/null || grep -ci "^processor" /proc/cpuinfo)
|
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"
|
[ "$c" = "1" ] || printf "%sx" "$c"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,14 +30,28 @@ __cpu_freq() {
|
||||||
fpdiv $hz "1000000" 1 # 1Ghz
|
fpdiv $hz "1000000" 1 # 1Ghz
|
||||||
freq="$_RET"
|
freq="$_RET"
|
||||||
elif [ -r "/proc/cpuinfo" ]; then
|
elif [ -r "/proc/cpuinfo" ]; then
|
||||||
if egrep -q -s -i -m 1 "^cpu MHz|^clock" /proc/cpuinfo; then
|
if egrep -q -s -i -m 1 "^cpu MHz|^clock" /compat/linux/proc/cpuinfo; then
|
||||||
freq=$(egrep -i -m 1 "^cpu MHz|^clock" /proc/cpuinfo | awk -F"[:.]" '{ printf "%01.1f", $2 / 1000 }')
|
freq=$(egrep -i -m 1 "^cpu MHz|^clock" /compat/linux/proc/cpuinfo | awk -F"[:.]" '{ printf "%01.1f", $2 / 1000 }')
|
||||||
else
|
else
|
||||||
# Must scale frequency by number of processors, if counting bogomips
|
# Must scale frequency by number of processors, if counting bogomips
|
||||||
count=$(getconf _NPROCESSORS_ONLN 2>/dev/null || grep -ci "^processor" /proc/cpuinfo)
|
count=$(getconf _NPROCESSORS_ONLN 2>/dev/null || grep -ci "^processor" /compat/linux/proc/cpuinfo)
|
||||||
freq=$(egrep -i -m 1 "^bogomips" /proc/cpuinfo | awk -F"[:.]" '{ print $2 }')
|
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}')
|
freq=$(printf "%s %s" "$freq" "$count" | awk '{printf "%01.1f\n", $1/$2/1000}')
|
||||||
fi
|
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
|
elif hz=$(sysctl -n hw.cpufrequency 2>/dev/null); then
|
||||||
fpdiv $hz "1000000000" 1 # 1Ghz
|
fpdiv $hz "1000000000" 1 # 1Ghz
|
||||||
freq="$_RET"
|
freq="$_RET"
|
||||||
|
|
|
@ -83,6 +83,10 @@ __logo() {
|
||||||
logo="<@>"
|
logo="<@>"
|
||||||
$MARKUP && printf "$(color b W g)%s$(color -)" "$logo" || printf "$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*)
|
*gentoo*)
|
||||||
logo=" > "
|
logo=" > "
|
||||||
$MARKUP && printf "$(color b c w)%s$(color -)" "$logo" || printf "$logo"
|
$MARKUP && printf "$(color b c w)%s$(color -)" "$logo" || printf "$logo"
|
||||||
|
|
|
@ -36,7 +36,7 @@ __memory() {
|
||||||
esac
|
esac
|
||||||
[ -n "${free}" -a -n "${total}" -a -n "${buffers}" -a -n "${cached}" ] && break;
|
[ -n "${free}" -a -n "${total}" -a -n "${buffers}" -a -n "${cached}" ] && break;
|
||||||
done < /proc/meminfo
|
done < /proc/meminfo
|
||||||
elif [ $(uname) = 'FreeBSD' ]; then
|
elif [ $(uname -s) = 'FreeBSD' ]; then
|
||||||
# FreeBSD support
|
# FreeBSD support
|
||||||
# Adapted from https://www.cyberciti.biz/files/scripts/freebsd-memory.pl.txt
|
# Adapted from https://www.cyberciti.biz/files/scripts/freebsd-memory.pl.txt
|
||||||
# Copyright (c) 2003-2004 Ralf S. Engelschall <rse@engelschall.com>
|
# Copyright (c) 2003-2004 Ralf S. Engelschall <rse@engelschall.com>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue