From 5c2f91ced231c3705d7ac63e5fd4abbb54867cb2 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Thu, 4 Aug 2022 23:55:07 +0200 Subject: [PATCH] bin: script adjustments --- .config/espanso/match/pass.yml | 42 ++++++++++++++++++++++------------ .config/shell/browse | 4 +++- .local/bin/scripts/bog | 8 ++++--- .local/bin/scripts/disktest | 17 ++++++++++---- .local/bin/scripts/edconf | 3 ++- .local/bin/scripts/xterm-bg.sh | 23 +++++++++++++++++++ 6 files changed, 73 insertions(+), 24 deletions(-) create mode 100755 .local/bin/scripts/xterm-bg.sh diff --git a/.config/espanso/match/pass.yml b/.config/espanso/match/pass.yml index 2555474..f14c8bc 100644 --- a/.config/espanso/match/pass.yml +++ b/.config/espanso/match/pass.yml @@ -30,6 +30,31 @@ matches: params: cmd: pass info/email/aur # {{{1 ADDRESS + - trigger: ";add" + replace: "{{output}}" + vars: + - name: output + type: shell + params: + cmd: pass info/address + - triggers: + - ";adb" + - ";adt" + replace: "{{output}}" + vars: + - name: output + type: shell + params: + cmd: pass info/address-bt + - triggers: + - ";adw" + - ";ads" + replace: "{{output}}" + vars: + - name: output + type: shell + params: + cmd: pass info/address-bt-short # Postal name - trigger: ";a0" replace: "{{output}}" @@ -78,6 +103,7 @@ matches: type: shell params: cmd: "pass info/address | tail -1 | cut -d' ' -f2" + # {{{1 NUMBERS - trigger: ";tel" replace: "{{output}}" vars: @@ -85,21 +111,6 @@ matches: type: shell params: cmd: pass info/phone - - trigger: ";adt" - replace: "{{output}}" - vars: - - name: output - type: shell - params: - cmd: pass info/address-bt - - trigger: ";add" - replace: "{{output}}" - vars: - - name: output - type: shell - params: - cmd: pass info/address - # {{{1 NUMBERS - trigger: ";tax" replace: "{{output}}" vars: @@ -129,6 +140,7 @@ matches: params: cmd: pass info/banking/dkb | head -1 # {{{1 EXTRAS + # TODO turn into emacs template - trigger: ";sigo" replace: |- #+ATTR_ORG: :width 200 diff --git a/.config/shell/browse b/.config/shell/browse index 35ac177..9c703f7 100644 --- a/.config/shell/browse +++ b/.config/shell/browse @@ -66,7 +66,9 @@ alias uloc='noglob sudo updatedb && loci' locei() { locate --all --basename "\\$1" "$@" | fselect } alias loce='noglob locei' # locate all -alias loca='noglob sudo updatedb -l 0 --prunenames "" --prunefs "tmpfs sysfs debugfs" --prunepaths "" -o /var/cache/locate-all.db && loci --database /var/cache/locate-all.db' +alias loca='noglob sudo updatedb -l 0 --prunenames "" --prunefs "tmpfs sysfs debugfs" --prunepaths "" -o /var/cache/locate-all.db && + sudo chmod +r /var/cache/locate-all.db && + loci --database /var/cache/locate-all.db' # ZOXIDE {{{1 alias c=z diff --git a/.local/bin/scripts/bog b/.local/bin/scripts/bog index bb3d470..62e92ad 100755 --- a/.local/bin/scripts/bog +++ b/.local/bin/scripts/bog @@ -1,7 +1,8 @@ -#!/bin/sh +#!/bin/sh -e # Simple backup with borg if test $# -eq 0 -then borg list --format "{barchive:40} Created {time}{NL}"; exit $? +then borg list --format "{barchive:40} Created {time}{NL}" + exit $? fi while test $# -gt 0; do case "$1" in @@ -15,7 +16,8 @@ while test $# -gt 0; do borg umount backups rm -d backups exit 0;; - (ls) borg list --short "::$2" | tree --fromfile . | less -F; exit $?;; + (tree) borg list --short "::$2" | tree --fromfile . | less -F + exit $?;; (-n) run=arg-test; shift;; (*_) prefix=$1; shift;; (*) break;; diff --git a/.local/bin/scripts/disktest b/.local/bin/scripts/disktest index 71da71c..27170a9 100755 --- a/.local/bin/scripts/disktest +++ b/.local/bin/scripts/disktest @@ -1,19 +1,28 @@ -#!/bin/sh -e +#!/bin/bash -e # Test disk performance # Adapted from https://www.shellhacks.com/disk-speed-test-read-write-hdd-ssd-perfomance-linux/ +# Using bash because of redirects test "$1" = "-w" && write=true && shift disk="${1:-$(df --output=source . | tail -1)}" if test "$write" then exec &> >(tee "disktest-$(date +%F)") fi +highlight() { echo "$1"; } + +highlight "Checking SMART with hdparm" # Needs sudo for read test sudo hdparm -MWAgt "$disk" + if test $# -eq 0 -then echo "Write test:" +then highlight "Write Test" sync # This prevents predictions by using random, but since that is too slow we have to copy a previously created file - # sudo dd status=progress if=/dev/random of=/var/tmp/tempfile bs=1M count=1K && sudo dd status=progress if=/var/tmp/tempfile of=tempfile bs=1M count=1K + highlight "Preparing:" && + sudo dd status=progress if=/dev/random of=/var/tmp/tempfile bs=1M count=1K && + highlight "Copying random bits:" && + sudo dd status=progress if=/var/tmp/tempfile of=tempfile bs=1M count=1K # TODO adjust size to disk - sudo dd status=progress if=/dev/zero of=tempfile bs=1000K count=1000 + highlight "Copying zero bits:" && + sudo dd status=progress if=/dev/zero of=tempfile bs=1M count=1K sudo rm tempfile fi diff --git a/.local/bin/scripts/edconf b/.local/bin/scripts/edconf index aa7cfdb..ea8175e 100755 --- a/.local/bin/scripts/edconf +++ b/.local/bin/scripts/edconf @@ -26,12 +26,13 @@ case "$sel" in ("") exit 1;; (/etc/sudoers) sudo visudo;; (/etc/fstab) sudoedit "$sel" && sudo findmnt --verify;; + #systemctl daemon-reload && mount -af -o remount;; (/etc/default/grub) sudoedit "$sel" && sudo grub-mkconfig -o /boot/grub/grub.cfg;; (/etc/locale.gen) sudoedit "$sel" && sudo locale-gen;; (/etc/nginx/*) sudoedit "$sel" && sudo nginx -t && sudo nginx -s reload;; (/etc/caddy/*) sudoedit "$sel" && caddy validate --config /etc/caddy/Caddyfile && sudo systemctl reload-or-restart caddy;; (/etc/ssh/*) sudoedit "$sel" && sudo systemctl reload-or-restart sshd;; (/etc/network/interfaces*) sudoedit "$sel" && sudo service networking reload;; - (*) $(test -w "$sel" || echo "sudo -E") edit "$sel";; + (*) edit "$sel";; esac echo "$sel" | cat - "$conf_cache" | head -20 >"$conf_tmp" && mv "$conf_tmp" "$conf_cache" diff --git a/.local/bin/scripts/xterm-bg.sh b/.local/bin/scripts/xterm-bg.sh new file mode 100755 index 0000000..4888e74 --- /dev/null +++ b/.local/bin/scripts/xterm-bg.sh @@ -0,0 +1,23 @@ +#!/bin/sh +# https://stackoverflow.com/questions/2507337/how-to-determine-a-terminals-background-color/30540928#30540928 +# Query a property from the terminal, e.g. background color. +# XTerm Operating System Commands +# "ESC ] Ps;Pt ST" + +oldstty=$(stty -g) + +# What to query? +# 11: text background +Ps=${1:-11} + +stty raw -echo min 0 time 0 +# stty raw -echo min 0 time 1 +printf "\033]$Ps;?\033\\" +# xterm needs the sleep (or "time 1", but that is 1/10th second). +sleep 0.01 +read -r answer +# echo $answer | cat -A +result=${answer#*;} +stty $oldstty +# Remove escape at the end. +echo $result | sed 's/[^rgb:0-9a-f/]\+$//'