From db7321af115a79b63267cb18889cbd334e8ca6e2 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Wed, 6 Dec 2023 20:58:18 +0100 Subject: scripts: Move many a script from sh to andy --- .local/bin/aqry | 22 ++++++++++------------ .local/bin/chkb | 2 +- .local/bin/lps | 14 +++++++------- .local/bin/mc-pass | 20 ++++++++++++-------- .local/bin/qotd | 4 ++-- .local/bin/send-package | 12 ++++++------ .local/bin/smail | 29 ++++++++++++++--------------- .local/bin/timer | 42 ++++++++++++++++++++---------------------- .local/bin/uni | 13 +++++-------- .local/sbin/chtz | 4 ++-- 10 files changed, 79 insertions(+), 83 deletions(-) diff --git a/.local/bin/aqry b/.local/bin/aqry index 6daef5d..38c70f3 100755 --- a/.local/bin/aqry +++ b/.local/bin/aqry @@ -1,15 +1,13 @@ -#!/bin/sh +#!/usr/local/bin/andy -set -e +set ADDR_FILE $(XDG_CONFIG_HOME:$HOME/.config)/aerc/addresses -readonly ADDR_FILE="${XDG_CONFIG_HOME:-$HOME/.config}/aerc/addresses" +awk -v qry=$args[1] ' + BEGIN { + FS = "\t" + } -awk -v qry="$1" ' -BEGIN { - FS = "\t" -} - -$1 ~ qry { - printf "%s\t%s\n", $2, $1 -} -' "$ADDR_FILE" + $1 ~ qry { + printf "%s\t%s\n", $2, $1 + } +' $ADDR_FILE diff --git a/.local/bin/chkb b/.local/bin/chkb index 359f443..e26133a 100755 --- a/.local/bin/chkb +++ b/.local/bin/chkb @@ -1,7 +1,7 @@ #!/usr/local/bin/andy set -e NOTIFY_LONG keyboard -set -e NOTIFY_SHORT chkb +set -e NOTIFY_SHORT `basename $args[0] set KEYBOARD at-translated-set-2-keyboard diff --git a/.local/bin/lps b/.local/bin/lps index 135848d..8e49fa5 100755 --- a/.local/bin/lps +++ b/.local/bin/lps @@ -1,9 +1,9 @@ -#!/bin/sh +#!/usr/local/bin/andy -set -e +set flags -m color -r 300 +if test $#args -ge 2 { + set flags $flags --area=0,0,$args[1],$args[1] +} -flags='-m color -r 300' -[ $# -eq 1 ] && flags="$flags --area=0,0,$1,$1" - -uri="$(lpoptions | sed -E 's/.*device-uri=hp:([^ ]+).*/hpaio:\1/')" -chronic hp-scan -d "$uri" $flags +set uri `lpoptions | sed -E 's/.*device-uri=hp:([^ ]+).*/hpaio:\1/' +chronic hp-scan -d $uri $flags diff --git a/.local/bin/mc-pass b/.local/bin/mc-pass index 168e62e..83b701b 100755 --- a/.local/bin/mc-pass +++ b/.local/bin/mc-pass @@ -1,14 +1,18 @@ -#!/bin/sh +#!/usr/local/bin/andy -export NOTIFY_LONG='mc pass' -export NOTIFY_SHORT="${0##*/}" +set -e NOTIFY_LONG 'mc pass' +set -e NOTIFY_SHORT `basename $args[0] -trap ' - wl-copy $tmp -addr="`mhdr -h from $tmp | sed -E '/.*<.*>$/s/.*<(.*)>$/\1/'`" -mbox="$MAILDIR/$addr/Sent" +set addr `mhdr -h from $tmp | sed -E '/.*<.*>$/s/.*<(.*)>$/\1/' +set mbox $MAILDIR/$addr/Sent -if msmtp -t --read-envelope-from <$tmp -then - mgenmid \ - | sed 's/^/Message-Id: /' \ - | cat - $tmp \ - | mmime \ - | mdeliver -cv "$mbox" \ +if msmtp -t --read-envelope-from <$tmp { + mgenmid + | sed 's/^/Message-Id: /' + | cat - $tmp + | mmime + | mdeliver -cv $mbox | xargs chronic mflag -S -fi +} diff --git a/.local/bin/timer b/.local/bin/timer index 4c33fb0..fc2652f 100755 --- a/.local/bin/timer +++ b/.local/bin/timer @@ -1,28 +1,26 @@ -#!/bin/sh +#!/usr/local/bin/andy -set -e - -abort() -{ - notify 'Timer Interrupted' 'The timer was unexpectedly interrupted' \ - -u critical - exit 1 +for sig in hup int quit abrt kill alrm term { + func sig$sig { + notify ( + 'Timer Interrupted' + 'The timer was unexpectedly interrupted' + -u critical + ) + exit 1 + } } -export NOTIFY_LONG=timer -export NOTIFY_SHORT=${0##*/} +set -e NOTIFY_LONG timer +set -e NOTIFY_SHORT `basename $args[0] -if [ $# -eq 0 ] -then - echo 'Usage: timer duration [message]' >&2 +if test $#args -lt 2 { + echo 'Usage: timer duration [message]' >/dev/stderr exit 1 -fi - -trap abort HUP INT QUIT ABRT KILL ALRM TERM +} -if sleep "$1" -then - notify 'Timer Finished' "$2" -else - abort -fi +if sleep $args[1] { + notify 'Timer Finished' $args[2] +} else { + sigint +} diff --git a/.local/bin/uni b/.local/bin/uni index a45b4c5..a882c8c 100755 --- a/.local/bin/uni +++ b/.local/bin/uni @@ -1,11 +1,11 @@ #!/usr/local/bin/andy -set -e NOTIFY_LONG unicode -set -e NOTIFY_SHORT uni +set -e NOTIFY_LONG unicode +set -e NOTIFY_SHORT `basename $args[0] func setup { curl 'https://www.unicode.org/Public/UNIDATA/UnicodeData.txt' - | sed -E r#' + | sed -E ' s/;[^;]*//2g s/\<(.)([A-Z]*)/\1\L\2/2g /^[^;]*;$DATA + ' >$DATA } -test $#XDG_DATA_HOME -gt 0 || set XDG_DATA_HOME $HOME/.local/share -set DATA $XDG_DATA_HOME/unicode-data +set DATA $(XDG_DATA_HOME:$HOME/.local/share)/unicode-data test -f $DATA || setup set i `{ @@ -33,5 +32,3 @@ if test -t 2 { } else { wtype -- $rune } - -# vi: ft=sh diff --git a/.local/sbin/chtz b/.local/sbin/chtz index 2033ab2..573cd9d 100755 --- a/.local/sbin/chtz +++ b/.local/sbin/chtz @@ -1,7 +1,7 @@ #!/usr/local/bin/andy -set -e NOTIFY_LONG timezone -set -e NOTIFY_SHORT chtz +set -e NOTIFY_LONG timezone +set -e NOTIFY_SHORT `basename $args[0] set choice `timedatectl list-timezones | grep ./. | osel sudo timedatectl set-timezone $choice -- cgit v1.2.3