bin: script adjustments

This commit is contained in:
xeruf 2022-08-04 23:55:07 +02:00
parent 31ef6a7109
commit 5c2f91ced2
6 changed files with 73 additions and 24 deletions

View File

@ -30,6 +30,31 @@ matches:
params: params:
cmd: pass info/email/aur cmd: pass info/email/aur
# {{{1 ADDRESS # {{{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 # Postal name
- trigger: ";a0" - trigger: ";a0"
replace: "{{output}}" replace: "{{output}}"
@ -78,6 +103,7 @@ matches:
type: shell type: shell
params: params:
cmd: "pass info/address | tail -1 | cut -d' ' -f2" cmd: "pass info/address | tail -1 | cut -d' ' -f2"
# {{{1 NUMBERS
- trigger: ";tel" - trigger: ";tel"
replace: "{{output}}" replace: "{{output}}"
vars: vars:
@ -85,21 +111,6 @@ matches:
type: shell type: shell
params: params:
cmd: pass info/phone 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" - trigger: ";tax"
replace: "{{output}}" replace: "{{output}}"
vars: vars:
@ -129,6 +140,7 @@ matches:
params: params:
cmd: pass info/banking/dkb | head -1 cmd: pass info/banking/dkb | head -1
# {{{1 EXTRAS # {{{1 EXTRAS
# TODO turn into emacs template
- trigger: ";sigo" - trigger: ";sigo"
replace: |- replace: |-
#+ATTR_ORG: :width 200 #+ATTR_ORG: :width 200

View File

@ -66,7 +66,9 @@ alias uloc='noglob sudo updatedb && loci'
locei() { locate --all --basename "\\$1" "$@" | fselect } locei() { locate --all --basename "\\$1" "$@" | fselect }
alias loce='noglob locei' alias loce='noglob locei'
# locate all # 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 # ZOXIDE {{{1
alias c=z alias c=z

View File

@ -1,7 +1,8 @@
#!/bin/sh #!/bin/sh -e
# Simple backup with borg # Simple backup with borg
if test $# -eq 0 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 fi
while test $# -gt 0; do while test $# -gt 0; do
case "$1" in case "$1" in
@ -15,7 +16,8 @@ while test $# -gt 0; do
borg umount backups borg umount backups
rm -d backups rm -d backups
exit 0;; 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;; (-n) run=arg-test; shift;;
(*_) prefix=$1; shift;; (*_) prefix=$1; shift;;
(*) break;; (*) break;;

View File

@ -1,19 +1,28 @@
#!/bin/sh -e #!/bin/bash -e
# Test disk performance # Test disk performance
# Adapted from https://www.shellhacks.com/disk-speed-test-read-write-hdd-ssd-perfomance-linux/ # 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 test "$1" = "-w" && write=true && shift
disk="${1:-$(df --output=source . | tail -1)}" disk="${1:-$(df --output=source . | tail -1)}"
if test "$write" if test "$write"
then exec &> >(tee "disktest-$(date +%F)") then exec &> >(tee "disktest-$(date +%F)")
fi fi
highlight() { echo "$1"; }
highlight "Checking SMART with hdparm"
# Needs sudo for read test # Needs sudo for read test
sudo hdparm -MWAgt "$disk" sudo hdparm -MWAgt "$disk"
if test $# -eq 0 if test $# -eq 0
then echo "Write test:" then highlight "Write Test"
sync sync
# This prevents predictions by using random, but since that is too slow we have to copy a previously created file # 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 # 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 sudo rm tempfile
fi fi

View File

@ -26,12 +26,13 @@ case "$sel" in
("") exit 1;; ("") exit 1;;
(/etc/sudoers) sudo visudo;; (/etc/sudoers) sudo visudo;;
(/etc/fstab) sudoedit "$sel" && sudo findmnt --verify;; (/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/default/grub) sudoedit "$sel" && sudo grub-mkconfig -o /boot/grub/grub.cfg;;
(/etc/locale.gen) sudoedit "$sel" && sudo locale-gen;; (/etc/locale.gen) sudoedit "$sel" && sudo locale-gen;;
(/etc/nginx/*) sudoedit "$sel" && sudo nginx -t && sudo nginx -s reload;; (/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/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/ssh/*) sudoedit "$sel" && sudo systemctl reload-or-restart sshd;;
(/etc/network/interfaces*) sudoedit "$sel" && sudo service networking reload;; (/etc/network/interfaces*) sudoedit "$sel" && sudo service networking reload;;
(*) $(test -w "$sel" || echo "sudo -E") edit "$sel";; (*) edit "$sel";;
esac esac
echo "$sel" | cat - "$conf_cache" | head -20 >"$conf_tmp" && mv "$conf_tmp" "$conf_cache" echo "$sel" | cat - "$conf_cache" | head -20 >"$conf_tmp" && mv "$conf_tmp" "$conf_cache"

23
.local/bin/scripts/xterm-bg.sh Executable file
View File

@ -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/]\+$//'