From 3e1a3df0fc55377d9e93bd45702ca747eafc46b4 Mon Sep 17 00:00:00 2001 From: Cian Bagshaw Date: Fri, 18 Aug 2023 02:04:46 +0100 Subject: [PATCH] Replaced third-party status scripts with my own --- .config/i3blocks | 23 +++++-------- .local/.gitignore | 3 -- .local/bin/.gitignore | 10 ------ .local/bin/cpuse | 15 +++++++++ .local/bin/memu | 12 +++++++ .local/bin/sb-memory | 69 --------------------------------------- .local/bin/sb-temperature | 69 --------------------------------------- .local/bin/stemp | 12 +++++++ .local/bin/udld | 11 +++++++ .local/bin/upt | 9 +++++ 10 files changed, 68 insertions(+), 165 deletions(-) delete mode 100644 .local/.gitignore delete mode 100644 .local/bin/.gitignore create mode 100755 .local/bin/cpuse create mode 100755 .local/bin/memu delete mode 100755 .local/bin/sb-memory delete mode 100755 .local/bin/sb-temperature create mode 100755 .local/bin/stemp create mode 100755 .local/bin/udld create mode 100755 .local/bin/upt diff --git a/.config/i3blocks b/.config/i3blocks index 0ae279d..2dabd9c 100644 --- a/.config/i3blocks +++ b/.config/i3blocks @@ -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 index 33fd564..0000000 --- a/.local/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -include -lib -share diff --git a/.local/bin/.gitignore b/.local/bin/.gitignore deleted file mode 100644 index acb66e2..0000000 --- a/.local/bin/.gitignore +++ /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 index 0000000..ad7e1c6 --- /dev/null +++ b/.local/bin/cpuse @@ -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 index 0000000..9004866 --- /dev/null +++ b/.local/bin/memu @@ -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 index 90eb2c6..0000000 --- a/.local/bin/sb-memory +++ /dev/null @@ -1,69 +0,0 @@ -#!/bin/sh -# Copyright (C) 2014 Julien Bonjean - -# 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 . - -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 index 2170f10..0000000 --- a/.local/bin/sb-temperature +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/env perl -# Copyright 2014 Pierre Mavro -# Copyright 2014 Vivien Didelot -# Copyright 2014 Andreas Guldstrand -# Copyright 2014 Benjamin Chretien - -# 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 . - -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 ] [-c ] [--chip ]\n"; - print "-w : warning threshold to become yellow\n"; - print "-c : critical threshold to become red\n"; - print "--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 () { - 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 index 0000000..26a1168 --- /dev/null +++ b/.local/bin/stemp @@ -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 index 0000000..7cab58a --- /dev/null +++ b/.local/bin/udld @@ -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 index 0000000..e7b9874 --- /dev/null +++ b/.local/bin/upt @@ -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; +} -- 2.20.1