added local bin
authorCian Bagshaw <cian@cianb.xyz>
Sun, 15 Jan 2023 16:42:55 +0000 (16:42 +0000)
committerCian Bagshaw <cian@cianb.xyz>
Sun, 15 Jan 2023 16:42:55 +0000 (16:42 +0000)
.local/.gitignore [new file with mode: 0644]
.local/bin/.gitignore [new file with mode: 0644]
.local/bin/sb-memory [new file with mode: 0755]
.local/bin/sb-temperature [new file with mode: 0755]
.local/bin/sb-volume [new file with mode: 0755]

diff --git a/.local/.gitignore b/.local/.gitignore
new file mode 100644 (file)
index 0000000..33fd564
--- /dev/null
@@ -0,0 +1,3 @@
+include
+lib
+share
diff --git a/.local/bin/.gitignore b/.local/bin/.gitignore
new file mode 100644 (file)
index 0000000..acb66e2
--- /dev/null
@@ -0,0 +1,10 @@
+electrum
+helpdev
+jp.py
+pip*
+qdarkstyle
+wal
+wheel
+
+sb-bandwidth
+sb-cpu
diff --git a/.local/bin/sb-memory b/.local/bin/sb-memory
new file mode 100755 (executable)
index 0000000..90eb2c6
--- /dev/null
@@ -0,0 +1,69 @@
+#!/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
new file mode 100755 (executable)
index 0000000..2170f10
--- /dev/null
@@ -0,0 +1,69 @@
+#!/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/sb-volume b/.local/bin/sb-volume
new file mode 100755 (executable)
index 0000000..e8e1372
--- /dev/null
@@ -0,0 +1,91 @@
+#!/usr/bin/env bash
+# Copyright (C) 2014 Julien Bonjean <julien@bonjean.info>
+# Copyright (C) 2014 Alexander Keller <github@nycroth.com>
+
+# 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/>.
+
+#------------------------------------------------------------------------
+
+# The second parameter overrides the mixer selection
+# For PulseAudio users, eventually use "pulse"
+# For Jack/Jack2 users, use "jackplug"
+# For ALSA users, you may use "default" for your primary card
+# or you may use hw:# where # is the number of the card desired
+if [[ -z "$MIXER" ]] ; then
+    MIXER="default"
+    if command -v pulseaudio >/dev/null 2>&1 && pulseaudio --check ; then
+        # pulseaudio is running, but not all installations use "pulse"
+        if amixer -D pulse info >/dev/null 2>&1 ; then
+            MIXER="pulse"
+        fi
+    fi
+    [ -n "$(lsmod | grep jack)" ] && MIXER="jackplug"
+    MIXER="${2:-$MIXER}"
+fi
+
+# The instance option sets the control to report and configure
+# This defaults to the first control of your selected mixer
+# For a list of the available, use `amixer -D $Your_Mixer scontrols`
+if [[ -z "$SCONTROL" ]] ; then
+    SCONTROL="${BLOCK_INSTANCE:-$(amixer -D $MIXER scontrols |
+                      sed -n "s/Simple mixer control '\([^']*\)',0/\1/p" |
+                      head -n1
+                    )}"
+fi
+
+# The first parameter sets the step to change the volume by (and units to display)
+# This may be in in % or dB (eg. 5% or 3dB)
+if [[ -z "$STEP" ]] ; then
+    STEP="${1:-5%}"
+fi
+
+# AMIXER(1):
+# "Use the mapped volume for evaluating the percentage representation like alsamixer, to be
+# more natural for human ear."
+NATURAL_MAPPING=${NATURAL_MAPPING:-0}
+if [[ "$NATURAL_MAPPING" != "0" ]] ; then
+    AMIXER_PARAMS="-M"
+fi
+
+#------------------------------------------------------------------------
+
+capability() { # Return "Capture" if the device is a capture device
+  amixer $AMIXER_PARAMS -D $MIXER get $SCONTROL |
+    sed -n "s/  Capabilities:.*cvolume.*/Capture/p"
+}
+
+volume() {
+  amixer $AMIXER_PARAMS -D $MIXER get $SCONTROL $(capability)
+}
+
+format() {
+  
+  perl_filter='if (/.*\[(\d+%)\] (\[(-?\d+.\d+dB)\] )?\[(on|off)\]/)'
+  perl_filter+='{CORE::say $4 eq "off" ? "MUTE" : "'
+  # If dB was selected, print that instead
+  perl_filter+=$([[ $STEP = *dB ]] && echo '$3' || echo '$1')
+  perl_filter+='"; exit}'
+  output=$(perl -ne "$perl_filter")
+  echo "$LABEL$output"
+}
+
+#------------------------------------------------------------------------
+
+case $BLOCK_BUTTON in
+  3) amixer $AMIXER_PARAMS -q -D $MIXER sset $SCONTROL $(capability) toggle ;;  # right click, mute/unmute
+  4) amixer $AMIXER_PARAMS -q -D $MIXER sset $SCONTROL $(capability) ${STEP}+ unmute ;; # scroll up, increase
+  5) amixer $AMIXER_PARAMS -q -D $MIXER sset $SCONTROL $(capability) ${STEP}- unmute ;; # scroll down, decrease
+esac
+
+volume | format