From d165601ffa27ef399d66d8548b4f89af2388aefb Mon Sep 17 00:00:00 2001 From: jason Date: Tue, 2 Apr 2024 18:05:33 -0600 Subject: add openbsd specific helper scripts --- scripts/obsd_termbar | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ scripts/openbsd_firefox | 35 +++++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100755 scripts/obsd_termbar create mode 100755 scripts/openbsd_firefox (limited to 'scripts') diff --git a/scripts/obsd_termbar b/scripts/obsd_termbar new file mode 100755 index 0000000..f1905b3 --- /dev/null +++ b/scripts/obsd_termbar @@ -0,0 +1,69 @@ +#!/bin/sh + +## Debug +# set -x + +# These will keep termbar running, but at the cost of leaving processes open +# when X dies. Helpful to use when tweaking +#trap 'exec $0' HUP # Restart itself +#trap 'tput cnorm; exit 1' INT QUIT TERM + +clock() { + CLOCK=$(date '+%a %d %b %H:%M:%S') +} + +workspace_id() { + WORKSPACE_ID=$(xprop -root 32c '\t$0' _NET_CURRENT_DESKTOP | cut -f 2) +} + +convert_to_hours() { + h=$((${1}/60)) + m=$((${1}%60)) + + printf "%02d:%02d" $h $m +} +bat() { + BAT_PCT=$(apm -l) + BAT_TIME=$(convert_to_hours $(apm -m)) + # ↯ ⋇ + + if [ $(sysctl hw.sensors.acpiac0.indicator0 | grep -c On) -eq "1" ]; then + AC_STATUS=PWR + else + AC_STATUS=BAT + fi + +} + +mem() { + MEM=$(top -n | grep Memory | awk {'print $3'}) +} + +cpu() { + _CPU_SPEED=$(sysctl hw.cpuspeed | cut -d "=" -f 2) + CPU_SPEED=$(bc -l -e scale=1 -e ${_CPU_SPEED}/1000 -e quit | awk '{printf "%.1f", $0}') + CPU_TEMP=$(sysctl hw.sensors.cpu0.temp0 | cut -d "=" -f 2 | cut -d "." -f 1) +} + +vol() { + _VOL=$(sndioctl output.level | cut -d "=" -f 2) + VOL=$(bc -l -e scale=1 -e ${_VOL}*100 -e quit | awk '{printf "%.1f\n", $0}') +} + +while true; do + clock + workspace_id + bat + cpu + mem + vol + + # Overwrites the input + clear + #tput cup 1 0 # tput sometimes leaves trailing numbers + # cinema display 193.110 + + printf "[${WORKSPACE_ID}] %188.110s CPU: ${CPU_SPEED}Ghz ${CPU_TEMP}C | MEM: ${MEM} | ${AC_STATUS} ${BAT_PCT}%% (${BAT_TIME}) | VOL: ${VOL}%% | ${CLOCK}" + + sleep 5 +done diff --git a/scripts/openbsd_firefox b/scripts/openbsd_firefox new file mode 100755 index 0000000..a34abcb --- /dev/null +++ b/scripts/openbsd_firefox @@ -0,0 +1,35 @@ +#!/bin/sh + +DATASIZE="10485760" +OPENFILES="400" + +xm_log() { + echo -n "$@\nDo you want to run Firefox anyway?\n\ +(If you don't increase these limits, Firefox might fail to work properly.)" | \ + xmessage -file - -center -buttons yes:0,no:1 -default no +} + + +# A stack overflow post said you also have to increase virtmem but that +# doesn't seem to be the case. If tabs start crashing then try increasing +# virtmem. + +#if [ $(ulimit -Sv) -lt ${DATASIZE} ]; then +# ulimit -Sv ${DATASIZE} || \ +# xm_log "Cannot increase virtualmem-cur to at least ${DATASIZE}" +# [ $? -eq 0 ] || exit +#fi + +if [ $(ulimit -Sd) -lt ${DATASIZE} ]; then + ulimit -Sd ${DATASIZE} || \ + xm_log "Cannot increase datasize-cur to at least ${DATASIZE}" + [ $? -eq 0 ] || exit +fi + +if [ $(ulimit -Sn) -lt ${OPENFILES} ]; then + ulimit -Sn ${OPENFILES} || \ + xm_log "Cannot increase openfiles-cur to at least ${OPENFILES}" + [ $? -eq 0 ] || exit +fi + +exec /usr/local/bin/firefox "${@}" -- cgit v1.2.1