From 5abeb6809753cb0d1829d17f626746558466e865 Mon Sep 17 00:00:00 2001 From: Deven Blake Date: Sun, 18 Jul 2021 01:28:48 -0400 Subject: [PATCH] NetBSD support and stuff --- dotfiles-old/bin/data | 80 ++++++++++++++++++++++++++++--------------- 1 file changed, 52 insertions(+), 28 deletions(-) diff --git a/dotfiles-old/bin/data b/dotfiles-old/bin/data index e107f39..54c1e4d 100755 --- a/dotfiles-old/bin/data +++ b/dotfiles-old/bin/data @@ -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 }