From 4063085286e6576785221a3f275479fbe6b7aeb4 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Thu, 27 Jul 2023 17:16:41 +0200 Subject: [PATCH] bin: update lots of shortcuts and add a few --- .bash_aliases | 3 +++ .config/shell/arch | 2 +- .config/shell/functions | 5 +++-- .local/bin/scripts/b | 1 + .local/bin/scripts/black | 1 + .local/bin/scripts/bog | 2 +- .local/bin/scripts/chexec | 2 +- .local/bin/scripts/focus | 1 + .local/bin/scripts/git-revive | 7 +++++++ .local/bin/scripts/help | 6 +++--- .local/bin/scripts/sign | 12 +++++++++--- .local/bin/scripts/test-colors | 10 ++++------ .local/bin/scripts/tl | 2 +- .local/bin/scripts/unlock | 3 +++ 14 files changed, 39 insertions(+), 18 deletions(-) create mode 100755 .local/bin/scripts/git-revive create mode 100755 .local/bin/scripts/unlock diff --git a/.bash_aliases b/.bash_aliases index 98d0805..8b400f6 100644 --- a/.bash_aliases +++ b/.bash_aliases @@ -9,6 +9,9 @@ alias sce="$sudo systemctl enable --now" alias sced="$sudo --preserve-env=EDITOR systemctl edit" alias scr="$sudo systemctl daemon-reload && $sudo systemctl reload-or-restart" +alias hist='history | less' +alias m='mv -vi' + highlight() { echo "$1"; } status() { highlight 'System' diff --git a/.config/shell/arch b/.config/shell/arch index 8fe00cd..567114f 100644 --- a/.config/shell/arch +++ b/.config/shell/arch @@ -44,7 +44,7 @@ yas() { ) if test -n "$pkg" then echo "Installing $pkg..." - cmd="yay -Sy --batchinstall --rebuild $pkg" + cmd="yay -Sy --batchinstall --rebuildtree $pkg" print -s "$cmd" eval "$cmd" rehash diff --git a/.config/shell/functions b/.config/shell/functions index 8dffdd8..299e417 100644 --- a/.config/shell/functions +++ b/.config/shell/functions @@ -66,6 +66,7 @@ sudos() { sudo "$(which $cmd)" "$@" } +# Outputs the resolved alias if it is a simple one-word alias resolvealias() { alias "$1" 2>/dev/null | sed -n "s|$1='\?\(noglob \)\?\([-A-z]\+\)'\?\$|\2|p" | grep -m 1 . || echo $1 } @@ -148,7 +149,7 @@ edit-shell() { # Edit an executable in the PATH edit-bin() { local toedit="$(resolvealias "$1")" - case "$toedit" in (*\ text*);; (*) toedit="$1";; esac + #case "$toedit" in (*\ text*);; (*) toedit="$1";; esac if f="$(which "$toedit" 2>/dev/null)" && test -f "$f" then edit "$f" else edit-shell -f "$toedit" @@ -474,7 +475,7 @@ alias updateUtils="updateDeps build.gradle.kts '"'"com.github.Xerus2000.util", " updateKarma() { rpl "karma-runner.github.io/[^/]\+/" "karma-runner.github.io/$1/"; } # Kill all shell background processes -alias killbg='kill ${${(v)jobstates##*:*:}%=*}' +alias killbg='kill -9 ${${(v)jobstates##*:*:}%=*}' # Kill all processes that match killm() { diff --git a/.local/bin/scripts/b b/.local/bin/scripts/b index 806ed48..733a2aa 100755 --- a/.local/bin/scripts/b +++ b/.local/bin/scripts/b @@ -11,6 +11,7 @@ # video thumbnails via mtn, pdf pages from pdftoppm # - text files are displayed through bat # Automatically requests elevation through sudo when needed +# TODO .raw,.iso,.qcow2 set -o pipefail diff --git a/.local/bin/scripts/black b/.local/bin/scripts/black index 65092dc..86b95ac 100755 --- a/.local/bin/scripts/black +++ b/.local/bin/scripts/black @@ -1,5 +1,6 @@ #!/bin/sh # Suspend screen until enter is pressed +test "$1" && sleep $1 xset dpms force off swaymsg "output * dpms off" read diff --git a/.local/bin/scripts/bog b/.local/bin/scripts/bog index 502ef82..a61f10a 100755 --- a/.local/bin/scripts/bog +++ b/.local/bin/scripts/bog @@ -17,7 +17,7 @@ while test $# -gt 0; do borg umount backups rm -d backups exit 0;; - (tree) borg list --short "::$2" | tree --fromfile . | less -F + (tree) borg list --short $(case $2 in (*::*) echo "$2";; (*) echo "::$2";; esac) | tree --fromfile . | less -F exit $?;; (-n) run=arg-test; shift;; (*_) prefix=$1; shift;; diff --git a/.local/bin/scripts/chexec b/.local/bin/scripts/chexec index da15623..a93c240 100755 --- a/.local/bin/scripts/chexec +++ b/.local/bin/scripts/chexec @@ -1,3 +1,3 @@ -#!/bin/sh -ex +#!/bin/sh # Set exec flag on all files that should be executable find -maxdepth 4 -name "*.sh" -o -path '*/githooks/*' "$@" -exec chmod -v +x {} + diff --git a/.local/bin/scripts/focus b/.local/bin/scripts/focus index 3aa3f14..8977ecb 100755 --- a/.local/bin/scripts/focus +++ b/.local/bin/scripts/focus @@ -4,6 +4,7 @@ # env: MUSIC # args: either a playlist file name, or a list of terms which all have to match # TODO fails on "Alchemy" +# TODO implement tags PLAYLISTS="${PLAYLISTS:-$MUSIC/Playlists}" mpc -q clear if test -z "$1" diff --git a/.local/bin/scripts/git-revive b/.local/bin/scripts/git-revive new file mode 100755 index 0000000..f1d96ac --- /dev/null +++ b/.local/bin/scripts/git-revive @@ -0,0 +1,7 @@ +#!/bin/sh -e +# Revives a file that has been deleted from the last known commit. +# Filename can be given with any amount of complete prefix directories. +file="$1" +commit=$(git log --format="%H" -1 -- "*/$file") +test -z "$commit" && echo "$file not found in history" >&2 && exit 2 +git restore --worktree --source="$commit~" -- $(git diff-tree --no-commit-id --name-only -r $commit | grep "/$file$") diff --git a/.local/bin/scripts/help b/.local/bin/scripts/help index 20a3c48..ce29384 100755 --- a/.local/bin/scripts/help +++ b/.local/bin/scripts/help @@ -26,15 +26,15 @@ showinfo() { cmd="$1" case "$cmd" in # TODO extract help in standard format from scripts - (hunt|rdoc|gh|chordpro|bat|pdfjam|reflector|topgrade|r128gain|7z|kubectl|diffr|docker|jrnl|difft|wiked-diff|qpdf) unbuffer "$@" --help | $paginate;; + (fwupdmgr|hunt|rdoc|gh|chordpro|bat|pdfjam|reflector|topgrade|r128gain|7z|kubectl|diffr|docker|jrnl|difft|wiked-diff|qpdf) unbuffer "$@" --help | sed 's|^[^ ].*:|\0|' | $paginate;; (caddy|stretchly|go|fossil|flutter) test "$cmd" = "fossil" -a $# -eq 1 && repo="$(locate -b -l 1 "fossil*.fossil")" && fossil ui "$repo" && exit # TODO view fossil ui in terminal shift "$cmd" help "$@" | $paginate;; # Non-standard help flags - (doom) "$@" --help;; + (doom) "$@" --help;; # Doom paginates itself (mpw) "$@" -h 2>&1 | $paginate;; - (plantuml|java) unbuffer "$@" -help | $paginate;; + (spectre|plantuml|java) unbuffer "$@" -help | $paginate;; (rails) { "$@" -H && "$@" --help; } | $paginate;; (vlc) shift && unbuffer vlc --full-help "$@" | $paginate;; (kdeconnect*) shift && kdeconnect-cli --help-all "$@" | $paginate;; diff --git a/.local/bin/scripts/sign b/.local/bin/scripts/sign index 92b5a2e..9c9cccc 100755 --- a/.local/bin/scripts/sign +++ b/.local/bin/scripts/sign @@ -3,11 +3,17 @@ test "$1" = "-q" && quiet=$1 && shift case "$1" in ([0-9]) page=$1; shift;; esac test ! -r "$1" && echo "Usage: sign [page] [hoffset (-160) [voffset (-310) [scale [signature-image]]]]" && exit 1 -signature=$(pass info/signature$(test -n "$5" && echo "-$5") || echo "$5") - -# TODO make filenames unique and don't rerun unneccessarily tmp_base=/tmp/sign mkdir -p $tmp_base + +texttopdf() { + out="$tmp_base/stamp.pdf" + echo "$1" | enscript -B -f Arial12 -o- | ps2pdf - >"$out" + echo "$out" +} +signature=$(test -f "$5" && echo "$5" || pass info/signature$(test -n "$5" && echo "-$5") || texttopdf "$5") + +# TODO make filenames unique and don't rerun unneccessarily tmp_signed=$tmp_base/$1_last-signature.pdf tmp_reversed=$tmp_base/$1_reverse.pdf sig=$tmp_base/signature_offset.pdf diff --git a/.local/bin/scripts/test-colors b/.local/bin/scripts/test-colors index 18c0154..97276c1 100755 --- a/.local/bin/scripts/test-colors +++ b/.local/bin/scripts/test-colors @@ -2,6 +2,7 @@ # https://stackoverflow.com/questions/4842424/list-of-ansi-color-escape-sequences/33206814#33206814 print("\\033[XXm") +print("-- Use Ctrl-V ESC if not using printf") for i in range(30,37+1): print("\033[%dm%d\t\t\033[%dm%d" % (i,i,i+30,i+30)); @@ -22,16 +23,13 @@ print(" ") def illustrate(command, *text): print("\033[", command, "m\\033[", command, "m - ", *text, sep="", end="\t") -def toggle(command, text): +def toggle(command, text, add = 20): illustrate(command, text, " on") - illustrate(command + 20, text, " off\033[0m") + illustrate(command + add, text, " off\033[0m") print() -toggle(1, "Bold") +toggle(1, "Bold", 21) toggle(2, "Grey") toggle(3, "Italic") toggle(4, "Underline") -#toggle(5, "Bold") -#toggle(6, "Bold") toggle(7, "Highlight") -#toggle(8, "Bold") toggle(9, "Strike") diff --git a/.local/bin/scripts/tl b/.local/bin/scripts/tl index 4c9fe27..ae7152a 100755 --- a/.local/bin/scripts/tl +++ b/.local/bin/scripts/tl @@ -6,4 +6,4 @@ # If first arg is a digit, it displaces the default depth of 3 # Any other arguments (usually pathnames) are passed on to the tree command case "$1" in ([0-9]) depth=$1; shift;; esac -tree -a --dirsfirst --du -h -C -L ${depth:-3} "$@" | ${PAGER:-less} -rF +tree --dirsfirst --du -h -C -L ${depth:-3} -I node_modules "$@" | ${PAGER:-less} -rF diff --git a/.local/bin/scripts/unlock b/.local/bin/scripts/unlock new file mode 100755 index 0000000..7402202 --- /dev/null +++ b/.local/bin/scripts/unlock @@ -0,0 +1,3 @@ +#!/bin/sh +# Unlock failed logins for user +faillock --user ${USER:-$1} --reset