Replaced third-party status scripts with my own
authorCian Bagshaw <cian@cianb.xyz>
Fri, 18 Aug 2023 01:04:46 +0000 (02:04 +0100)
committerCian Bagshaw <cian@cianb.xyz>
Fri, 18 Aug 2023 01:04:46 +0000 (02:04 +0100)
.config/i3blocks
.local/.gitignore [deleted file]
.local/bin/.gitignore [deleted file]
.local/bin/cpuse [new file with mode: 0755]
.local/bin/memu [new file with mode: 0755]
.local/bin/sb-memory [deleted file]
.local/bin/sb-temperature [deleted file]
.local/bin/stemp [new file with mode: 0755]
.local/bin/udld [new file with mode: 0755]
.local/bin/upt [new file with mode: 0755]

index 0ae279d..2dabd9c 100644 (file)
@@ -1,10 +1,6 @@
-[name]
-command=echo $USER@$(hostname)
-label=  
-interval=once
-
 [uptime]
-command=uptime -p
+command=upt
+label= 
 interval=60
 
 [speaker volume]
@@ -18,25 +14,24 @@ label=
 interval=10
 
 [memory]
-command=sb-memory
+command=memu
 label= 
 interval=20
 
 [cpu]
-command=sb-cpu -t 5 -l  
-markup=pango
-interval=persist
+command=cpuse
+label= 
+interval=10
 
 [temperature]
-command=sb-temperature
+command=stemp k10temp amdgpu
 label=  
 interval=10
 
 [bandwidth]
-command=sb-bandwidth -B -s -t 5
+command=udld
 label= 
-markup=pango
-interval=persist
+interval=10
 
 [ip]
 command=hostname -i
diff --git a/.local/.gitignore b/.local/.gitignore
deleted file mode 100644 (file)
index 33fd564..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-include
-lib
-share
diff --git a/.local/bin/.gitignore b/.local/bin/.gitignore
deleted file mode 100644 (file)
index acb66e2..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-electrum
-helpdev
-jp.py
-pip*
-qdarkstyle
-wal
-wheel
-
-sb-bandwidth
-sb-cpu
diff --git a/.local/bin/cpuse b/.local/bin/cpuse
new file mode 100755 (executable)
index 0000000..ad7e1c6
--- /dev/null
@@ -0,0 +1,15 @@
+#!/bin/awk -f
+# cpuse - print average cpu usage since last run
+
+BEGIN {
+       getline < "/tmp/cpuse";
+       ou=$1; ot=$2;
+       while (getline < "/proc/stat") {
+               if ($1 == "cpu") {
+                       u=$2+$3+$4+$7+$8+$9+$10+$11; t=u+$5+$6;
+                       print u,t > "/tmp/cpuse";
+                       printf "%i%%\n", ((u-ou)*100)/(t-ot);
+                       exit;
+               }
+       }
+}
diff --git a/.local/bin/memu b/.local/bin/memu
new file mode 100755 (executable)
index 0000000..9004866
--- /dev/null
@@ -0,0 +1,12 @@
+#!/bin/awk -f
+# memu - print memory usage 
+
+BEGIN {
+    while (getline < "/proc/meminfo") {
+        if ($1 == "MemTotal:")  t=$2;
+        if ($1 == "MemAvailable:") {
+            printf "%.1fG/%.1fG\n", (t-$2)/1000000, t/1000000;
+            exit;
+        }
+    }
+}
diff --git a/.local/bin/sb-memory b/.local/bin/sb-memory
deleted file mode 100755 (executable)
index 90eb2c6..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-#!/bin/sh
-# Copyright (C) 2014 Julien Bonjean <julien@bonjean.info>
-
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-TYPE="${BLOCK_INSTANCE:-mem}"
-
-awk -v type=$TYPE '
-/^MemTotal:/ {
-       mem_total=$2
-}
-/^MemFree:/ {
-       mem_free=$2
-}
-/^Buffers:/ {
-       mem_free+=$2
-}
-/^Cached:/ {
-       mem_free+=$2
-}
-/^SwapTotal:/ {
-       swap_total=$2
-}
-/^SwapFree:/ {
-       swap_free=$2
-}
-END {
-       if (type == "swap") {
-               free=swap_free/1024/1024
-               used=(swap_total-swap_free)/1024/1024
-               total=swap_total/1024/1024
-       } else {
-               free=mem_free/1024/1024
-               used=(mem_total-mem_free)/1024/1024
-               total=mem_total/1024/1024
-       }
-
-       pct=0
-       if (total > 0) {
-               pct=used/total*100
-       }
-
-       # full text
-       printf("%.1fG/%.1fG (%.f%%)\n", used, total, pct)
-
-       # short text
-       printf("%.f%%\n", pct)
-
-       # color
-       if (pct > 90) {
-               print("#FF0000")
-       } else if (pct > 80) {
-               print("#FFAE00")
-       } else if (pct > 70) {
-               print("#FFF600")
-       }
-}
-' /proc/meminfo
diff --git a/.local/bin/sb-temperature b/.local/bin/sb-temperature
deleted file mode 100755 (executable)
index 2170f10..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-#!/usr/bin/env perl
-# Copyright 2014 Pierre Mavro <deimos@deimos.fr>
-# Copyright 2014 Vivien Didelot <vivien@didelot.org>
-# Copyright 2014 Andreas Guldstrand <andreas.guldstrand@gmail.com>
-# Copyright 2014 Benjamin Chretien <chretien at lirmm dot fr>
-
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-use strict;
-use warnings;
-use utf8;
-use Getopt::Long;
-
-binmode(STDOUT, ":utf8");
-
-# default values
-my $t_warn = $ENV{T_WARN} || 70;
-my $t_crit = $ENV{T_CRIT} || 90;
-my $chip = $ENV{SENSOR_CHIP} || "";
-my $temperature = -9999;
-
-sub help {
-    print "Usage: temperature [-w <warning>] [-c <critical>] [--chip <chip>]\n";
-    print "-w <percent>: warning threshold to become yellow\n";
-    print "-c <percent>: critical threshold to become red\n";
-    print "--chip <chip>: sensor chip\n";
-    exit 0;
-}
-
-GetOptions("help|h" => \&help,
-           "w=i"    => \$t_warn,
-           "c=i"    => \$t_crit,
-           "chip=s" => \$chip);
-
-# Get chip temperature
-open (SENSORS, "sensors -u $chip |") or die;
-while (<SENSORS>) {
-    if (/^\s+temp1_input:\s+[\+]*([\-]*\d+\.\d)/) {
-        $temperature = $1;
-        last;
-    }
-}
-close(SENSORS);
-
-$temperature eq -9999 and die 'Cannot find temperature';
-
-# Print short_text, full_text
-print "$temperature°C\n" x2;
-
-# Print color, if needed
-if ($temperature >= $t_crit) {
-    print "#FF0000\n";
-    exit 33;
-} elsif ($temperature >= $t_warn) {
-    print "#FFFC00\n";
-}
-
-exit 0;
diff --git a/.local/bin/stemp b/.local/bin/stemp
new file mode 100755 (executable)
index 0000000..26a1168
--- /dev/null
@@ -0,0 +1,12 @@
+#!/bin/sh
+# stemp - print system/sensor temperature
+# $1: sensor name(s) (optional)
+
+for f in /sys/class/hwmon/hwmon*; do
+       paste "$f/name" "$f/temp1_input" 2>/dev/null
+done | if [ -z "$1" ]; then
+       awk '{printf "%s\t%i°C\n",$1,$2/1000}'
+else
+       awk -v n="$*" 'BEGIN {gsub(" ","|",n)} \
+               $1~n {printf "%i°C ",$2/1000} END {printf "\n"}'
+fi
diff --git a/.local/bin/udld b/.local/bin/udld
new file mode 100755 (executable)
index 0000000..7cab58a
--- /dev/null
@@ -0,0 +1,11 @@
+#!/bin/awk -f
+
+BEGIN {
+       while ("for f in /sys/class/net/[ew]*; do paste $f/statistics/[rt]x_bytes; done" | getline) {
+               d+=$1; u+=$2; }
+       getline < "/tmp/test"; od=$1; ou=$2; ot=$3;
+       getline < "/proc/uptime"; t=$1;
+       print d,u,t > "/tmp/test";
+       t=t-ot; if (!t) t=1;
+       printf "%.1f/%.1f MB/s\n", ((d-od)/1000000)/t, ((u-ou)/1000000)/t;
+}
diff --git a/.local/bin/upt b/.local/bin/upt
new file mode 100755 (executable)
index 0000000..e7b9874
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/awk -f
+# upt - print uptime in short
+
+BEGIN {
+       getline < "/proc/uptime";
+       m=$1/60; h=0;
+       if (m >= 60) { h=int(m/60); m-=h*60; }
+       printf "%ih %im\n", h, m;
+}