Update 2022-12-05 22:26 OpenBSD/amd64
This commit is contained in:
parent
e5a3d424cc
commit
6d98d9881a
18
.bin/avg.c
Normal file
18
.bin/avg.c
Normal file
@ -0,0 +1,18 @@
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
double no = 0;
|
||||
for (int i=0; i<argc; i++) {
|
||||
no += atoi(argv[i]) / 1000000;
|
||||
}
|
||||
if (argc < 2)
|
||||
printf("%f\n", no);
|
||||
|
||||
if (argc > 1)
|
||||
printf("%.0f\n", no / (argc - 1));
|
||||
|
||||
return 0;
|
||||
}
|
30
.bin/dev-here
Executable file
30
.bin/dev-here
Executable file
@ -0,0 +1,30 @@
|
||||
#!/bin/sh
|
||||
. ~/.bin/_config
|
||||
doas chown -R sdk ${DEVDIRPATH}
|
||||
set -xe
|
||||
|
||||
# save dev bookmark
|
||||
DEVDIR="${PWD}"
|
||||
echo "${DEVDIR}" > "${DEVDIRPATH}/dir"
|
||||
|
||||
# create files list
|
||||
find "${DEVDIR}" -type f \
|
||||
\( -name "*.c" \
|
||||
-o -name "*.cc" \
|
||||
-o -name "*.cpp" \
|
||||
-o -name "*.c" \
|
||||
-o -name "*.h" \
|
||||
-o -name "*.hh" \
|
||||
-o -name "*.hpp" \
|
||||
\) > ${DEVDIRPATH}/files
|
||||
|
||||
# create cscope database
|
||||
cscope -qbkCRvf ${DEVDIRPATH}/cscope.out -i${DEVDIRPATH}/files
|
||||
|
||||
# create tags file
|
||||
ectags --sort=yes \
|
||||
--fields=afiksSt \
|
||||
--extra=fq \
|
||||
--totals=yes \
|
||||
-L ${DEVDIRPATH}/files \
|
||||
-f ${DEVDIRPATH}/tags
|
29
.bin/dev-here-with-system-includes
Executable file
29
.bin/dev-here-with-system-includes
Executable file
@ -0,0 +1,29 @@
|
||||
#!/bin/sh
|
||||
. ~/.bin/_config
|
||||
doas chown -R sdk /home/sdk/.dev
|
||||
set -xe
|
||||
|
||||
# save dev bookmark
|
||||
DEVDIR="${PWD}"
|
||||
echo "${DEVDIR}" > "/home/sdk/.dev/dir"
|
||||
|
||||
# create files list
|
||||
find "${DEVDIR}" /usr/include /usr/local/include -type f \
|
||||
\( -name "*.c" \
|
||||
-o -name "*.cc" \
|
||||
-o -name "*.cpp" \
|
||||
-o -name "*.c" \
|
||||
-o -name "*.hh" \
|
||||
-o -name "*.hpp" \
|
||||
\) > /home/sdk/.dev/files
|
||||
|
||||
# create cscope database
|
||||
cscope -qbkCRvf /home/sdk/.dev/cscope.out -i/home/sdk/.dev/files
|
||||
|
||||
# create tags file
|
||||
ectags --sort=yes \
|
||||
--fields=afiksSt \
|
||||
--extra=fq \
|
||||
--totals=yes \
|
||||
-L /home/sdk/.dev/files \
|
||||
-f /home/sdk/.dev/tags
|
74
.config/spectrwm/cbar.c
Normal file
74
.config/spectrwm/cbar.c
Normal file
@ -0,0 +1,74 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <wchar.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/sensors.h>
|
||||
|
||||
#include <machine/apmvar.h>
|
||||
|
||||
|
||||
static int battery_percent = 50;
|
||||
static int cpu_temp = 46;
|
||||
static int fan_speed = 3392;
|
||||
static int cpu_base_speed = 2501;
|
||||
static int cpu_avg_speed = 468;
|
||||
|
||||
void update_fan_speed() {
|
||||
struct sensor sensor;
|
||||
size_t slen = sizeof(sensor);
|
||||
// XXX hw.sensors.acpithinkpad0.fan0
|
||||
int mib[5] = { CTL_HW, HW_SENSORS, 5, SENSOR_FANRPM, 0 }; // Lenovo x230
|
||||
if (sysctl(mib, 5, &sensor, &slen, NULL, 0) != -1)
|
||||
fan_speed = sensor.value;
|
||||
fan_speed = -1;
|
||||
}
|
||||
|
||||
void update_cpu_temp() {
|
||||
struct sensor sensor;
|
||||
size_t slen = sizeof(sensor);
|
||||
// XXX hw.sensors.cpu0.temp0
|
||||
int mib[5] = { CTL_HW, HW_SENSORS, 0, SENSOR_TEMP, 0 }; // Lenovo x230
|
||||
if (sysctl(mib, 5, &sensor, &slen, NULL, 0) != -1)
|
||||
cpu_temp = (sensor.value - 273150000) / 1000000.0;
|
||||
cpu_temp = -1;
|
||||
}
|
||||
|
||||
void update_battery() {
|
||||
int fd;
|
||||
struct apm_power_info pi;
|
||||
|
||||
if ((fd = open("/dev/apm", O_RDONLY)) == -1 ||
|
||||
ioctl(fd, APM_IOC_GETPOWER, &pi) == -1 ||
|
||||
close(fd) == -1)
|
||||
battery_percent = -1;
|
||||
|
||||
if (pi.battery_state == APM_BATT_UNKNOWN ||
|
||||
pi.battery_state == APM_BATTERY_ABSENT)
|
||||
battery_percent = -1;
|
||||
|
||||
battery_percent = pi.battery_life;
|
||||
}
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
|
||||
while(1) {
|
||||
update_battery();
|
||||
update_cpu_temp();
|
||||
update_fan_speed();
|
||||
wprintf(L"%s %d%% %s %dC %s %4dRPM %s %4dMhz (~%4dMhz) %s\n",
|
||||
"", battery_percent,
|
||||
" ", cpu_temp,
|
||||
" ", fan_speed,
|
||||
" ", cpu_base_speed, cpu_avg_speed,
|
||||
" ");
|
||||
sleep(1);
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -1,40 +1,42 @@
|
||||
#!/bin/ksh
|
||||
|
||||
linux_server() {
|
||||
while true
|
||||
do
|
||||
printf " %s %3s%% %s°C %s (priv) %4sMhz \n" \
|
||||
"$(who | cut -d" " -f1 | sort -u | wc -l)" \
|
||||
"$(ps -u d034266 -o pcpu | awk '/[0-9\.]/ { s=s+$1 } END { printf("%.0d\n", s); }')" \
|
||||
"$(sensors | awk '/^Core/ { s=$3+s } END { printf("%2d\n", s/60); }')" \
|
||||
"$(df -h --output=avail /priv/ | tail -1)" \
|
||||
"$(lscpu | awk '/^CPU MHz:/ { printf("%.4d", $3) }')"
|
||||
sleep 5
|
||||
done
|
||||
while true
|
||||
do
|
||||
printf " %s %3s%% %s°C %s (priv) %4sMhz \n" \
|
||||
"$(who | cut -d" " -f1 | sort -u | wc -l)" \
|
||||
"$(ps -u d034266 -o pcpu | awk '/[0-9\.]/ { s=s+$1 } END { printf("%.0d\n", s); }')" \
|
||||
"$(sensors | awk '/^Core/ { s=$3+s } END { printf("%2d\n", s/60); }')" \
|
||||
"$(df -h --output=avail /priv/ | tail -1)" \
|
||||
"$(lscpu | awk '/^CPU MHz:/ { printf("%.4d", $3) }')"
|
||||
sleep 5
|
||||
done
|
||||
}
|
||||
|
||||
openbsd_laptop() {
|
||||
out() { printf '%s/1000/1000\n' "$1" | bc; }
|
||||
while true
|
||||
do
|
||||
set -A _SYSV -- $(sysctl -n hw.sensors.cpu0.temp0 \
|
||||
hw.sensors.acpithinkpad0.fan0 \
|
||||
hw.cpuspeed \
|
||||
| cut -d" " -f1)
|
||||
|
||||
_TMP="$(sysctl -n hw.sensors.cpu{0,1,2,3,4,5,6,7,8,9,10,11}.frequency0 \
|
||||
| cut -d. -f1)"
|
||||
|
||||
AVG="$(printf '(%s)/12' "$_TMP" | tr '\n' '+')"
|
||||
|
||||
printf " %s%% %2s°C %4sRPM %4sMhz (~%4sMhz) \n" \
|
||||
"$(apm -l)" "${_SYSV[0]}" "${_SYSV[1]}" "${_SYSV[2]}" "$(out $AVG)";
|
||||
sleep 5
|
||||
done
|
||||
while true
|
||||
do
|
||||
set -A _SYSV -- $(sysctl -n \
|
||||
hw.sensors.cpu0.temp0 \
|
||||
hw.sensors.acpithinkpad0.fan0 \
|
||||
hw.cpuspeed \
|
||||
| cut -d" " -f1)
|
||||
|
||||
set -A _CPUV -- $(sysctl -n \
|
||||
hw.sensors.cpu{0,1,2,3,4,5,6,7,8,9,10,11}.frequency0 \
|
||||
| cut -d"." -f1)
|
||||
|
||||
AVG=$(avg "${_CPUV[@]}")
|
||||
|
||||
printf " %s%% %2s°C %4sRPM %4sMhz (~%4.4sMhz) \n" \
|
||||
"$(apm -l)" "${_SYSV[0]}" "${_SYSV[1]}" "${_SYSV[2]}" "${AVG}";
|
||||
|
||||
sleep 5
|
||||
done
|
||||
}
|
||||
|
||||
case $(hostname) in
|
||||
ld*) linux_server; ;;
|
||||
*.home.codevoid.de) openbsd_laptop; ;;
|
||||
ld*) linux_server; ;;
|
||||
*.home.codevoid.de) openbsd_laptop; ;;
|
||||
esac
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user