1
0

NetBSD support and stuff

This commit is contained in:
dtb 2021-07-18 01:28:48 -04:00
parent 1cc0c3418e
commit 5abeb68097

View File

@ -15,6 +15,8 @@ CPU_TEMP_SCALE=1000
# format for the date (by default in this script, ISO 8601)
alias date="date '+%Y-%m-%dT%T'"
DELIMITER=" || "
# how fast to refresh the display (in seconds, will be substituted with 1 if
# not an integer)
INTERVAL=1
@ -29,33 +31,51 @@ INTERVAL=1
PUBLIC_IP_FETCH_URL="http://ifconfig.io/"
get_battery_status() {
# this is a dirty hack.
# acpi | awk '{print $4}' will print the battery percentage,
# and s/,$// strips the trailing comma.
# acpi -a will just print the power adapter status.
printf "%b" "$(acpi | awk '{print $4}' | sed 's/,$//') ($(acpi -a))"
return
if [ "$(uname)" = "Linux" ]; then
# this is a dirty hack.
# acpi | awk '{print $4}' will print the battery percentage,
# and s/,$// strips the trailing comma.
# acpi -a will just print the power adapter status.
printf "%b" "$(acpi | awk '{print $4}' | sed 's/,$//') ($(acpi -a))"
return
fi
}
get_cpu_temp() {
RETVAL=""
# iterate over files, adjust, print out "%dC "
for file in $CPU_TEMP_FILES;
do RETVAL="$RETVAL$(fdivide $(cat $file) $CPU_TEMP_SCALE)C "
done
# in-line python (bet you've never seen that before) that
# strips off trailing whitespace. could be done with sed but
# this was more fun
printf "%b" "$RETVAL" \
| python -c "from sys import stdin; print(stdin.read().rstrip() + '\n')"
return
if [ "$(uname)" = "Linux" ]; then
RETVAL=""
# iterate over files, adjust, print out "%dC "
for file in $CPU_TEMP_FILES;
do RETVAL="$RETVAL$(fdivide $(cat $file) $CPU_TEMP_SCALE)C "
done
# in-line python (bet you've never seen that before) that
# strips off trailing whitespace. could be done with sed but
# this was more fun
printf "%b" "$RETVAL" \
| python -c "from sys import stdin; print(stdin.read().rstrip() + '\n')"
return
elif [ "$(uname)" = "NetBSD" ]; then
printf "%bC" "$(envstat -s coretemp0:'cpu0 temperature' \
| sed 1,2d \
| cut -d ':' -f 2 \
| awk '{print $1}' \
| cut -d '.' -f 1)"
fi
}
get_current_desktop() {
case "$WM" in
(bspwm) bspc query -D -d focused --names ;;
esac
}
get_memory_usage() {
printf "%b" \
"$(free | head -n 2 | tail -n 1 \
| awk '{print $3 " used / " $2 " total"}')"
return
if [ "$(uname)" = "Linux" ]; then
printf "%b" \
"$(free | head -n 2 | tail -n 1 \
| awk '{print $3 " used / " $2 " total"}')"
return
fi
}
get_public_ip() {
@ -68,13 +88,17 @@ get_public_ip() {
PUBLIC_IP="$(get_public_ip)"
printbar() {
printf "%b || %b || %b || %b || %b %b\n" \
"$(date)" \
"BAT: $(get_battery_status)" \
"CPU: $(get_cpu_temp)" \
"PuIP: $PUBLIC_IP" \
"MEM: $(get_memory_usage)" \
""
printf "[%b] " "$(get_current_desktop)"
printf "%b" "$(date)"
#printf "%b" "$DELIMITER"
#printf "%b" "BAT: $(get_battery_status)"
printf "%b" "$DELIMITER"
printf "%b" "CPU: $(get_cpu_temp)"
printf "%b" "$DELIMITER"
printf "%b" "PuIP: $PUBLIC_IP"
#printf "%b" "$DELIMITER"
#printf "%b" "MEM: $(get_memory_usage)"
printf "\n"
return
}