bin: update lots of shortcuts and add a few

This commit is contained in:
xeruf 2023-07-27 17:16:41 +02:00
parent e46ecf6f3f
commit 4063085286
14 changed files with 39 additions and 18 deletions

View File

@ -9,6 +9,9 @@ alias sce="$sudo systemctl enable --now"
alias sced="$sudo --preserve-env=EDITOR systemctl edit" alias sced="$sudo --preserve-env=EDITOR systemctl edit"
alias scr="$sudo systemctl daemon-reload && $sudo systemctl reload-or-restart" alias scr="$sudo systemctl daemon-reload && $sudo systemctl reload-or-restart"
alias hist='history | less'
alias m='mv -vi'
highlight() { echo "$1"; } highlight() { echo "$1"; }
status() { status() {
highlight 'System' highlight 'System'

View File

@ -44,7 +44,7 @@ yas() {
) )
if test -n "$pkg" if test -n "$pkg"
then echo "Installing $pkg..." then echo "Installing $pkg..."
cmd="yay -Sy --batchinstall --rebuild $pkg" cmd="yay -Sy --batchinstall --rebuildtree $pkg"
print -s "$cmd" print -s "$cmd"
eval "$cmd" eval "$cmd"
rehash rehash

View File

@ -66,6 +66,7 @@ sudos() {
sudo "$(which $cmd)" "$@" sudo "$(which $cmd)" "$@"
} }
# Outputs the resolved alias if it is a simple one-word alias
resolvealias() { resolvealias() {
alias "$1" 2>/dev/null | sed -n "s|$1='\?\(noglob \)\?\([-A-z]\+\)'\?\$|\2|p" | grep -m 1 . || echo $1 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 an executable in the PATH
edit-bin() { edit-bin() {
local toedit="$(resolvealias "$1")" 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" if f="$(which "$toedit" 2>/dev/null)" && test -f "$f"
then edit "$f" then edit "$f"
else edit-shell -f "$toedit" 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/"; } updateKarma() { rpl "karma-runner.github.io/[^/]\+/" "karma-runner.github.io/$1/"; }
# Kill all shell background processes # Kill all shell background processes
alias killbg='kill ${${(v)jobstates##*:*:}%=*}' alias killbg='kill -9 ${${(v)jobstates##*:*:}%=*}'
# Kill all processes that match # Kill all processes that match
killm() { killm() {

View File

@ -11,6 +11,7 @@
# video thumbnails via mtn, pdf pages from pdftoppm # video thumbnails via mtn, pdf pages from pdftoppm
# - text files are displayed through bat # - text files are displayed through bat
# Automatically requests elevation through sudo when needed # Automatically requests elevation through sudo when needed
# TODO .raw,.iso,.qcow2
set -o pipefail set -o pipefail

View File

@ -1,5 +1,6 @@
#!/bin/sh #!/bin/sh
# Suspend screen until enter is pressed # Suspend screen until enter is pressed
test "$1" && sleep $1
xset dpms force off xset dpms force off
swaymsg "output * dpms off" swaymsg "output * dpms off"
read read

View File

@ -17,7 +17,7 @@ while test $# -gt 0; do
borg umount backups borg umount backups
rm -d backups rm -d backups
exit 0;; 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 $?;; exit $?;;
(-n) run=arg-test; shift;; (-n) run=arg-test; shift;;
(*_) prefix=$1; shift;; (*_) prefix=$1; shift;;

View File

@ -1,3 +1,3 @@
#!/bin/sh -ex #!/bin/sh
# Set exec flag on all files that should be executable # Set exec flag on all files that should be executable
find -maxdepth 4 -name "*.sh" -o -path '*/githooks/*' "$@" -exec chmod -v +x {} + find -maxdepth 4 -name "*.sh" -o -path '*/githooks/*' "$@" -exec chmod -v +x {} +

View File

@ -4,6 +4,7 @@
# env: MUSIC # env: MUSIC
# args: either a playlist file name, or a list of terms which all have to match # args: either a playlist file name, or a list of terms which all have to match
# TODO fails on "Alchemy" # TODO fails on "Alchemy"
# TODO implement tags
PLAYLISTS="${PLAYLISTS:-$MUSIC/Playlists}" PLAYLISTS="${PLAYLISTS:-$MUSIC/Playlists}"
mpc -q clear mpc -q clear
if test -z "$1" if test -z "$1"

7
.local/bin/scripts/git-revive Executable file
View File

@ -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$")

View File

@ -26,15 +26,15 @@ showinfo() {
cmd="$1" cmd="$1"
case "$cmd" in case "$cmd" in
# TODO extract help in standard format from scripts # 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 (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 # TODO view fossil ui in terminal
shift shift
"$cmd" help "$@" | $paginate;; "$cmd" help "$@" | $paginate;;
# Non-standard help flags # Non-standard help flags
(doom) "$@" --help;; (doom) "$@" --help;; # Doom paginates itself
(mpw) "$@" -h 2>&1 | $paginate;; (mpw) "$@" -h 2>&1 | $paginate;;
(plantuml|java) unbuffer "$@" -help | $paginate;; (spectre|plantuml|java) unbuffer "$@" -help | $paginate;;
(rails) { "$@" -H && "$@" --help; } | $paginate;; (rails) { "$@" -H && "$@" --help; } | $paginate;;
(vlc) shift && unbuffer vlc --full-help "$@" | $paginate;; (vlc) shift && unbuffer vlc --full-help "$@" | $paginate;;
(kdeconnect*) shift && kdeconnect-cli --help-all "$@" | $paginate;; (kdeconnect*) shift && kdeconnect-cli --help-all "$@" | $paginate;;

View File

@ -3,11 +3,17 @@ test "$1" = "-q" && quiet=$1 && shift
case "$1" in ([0-9]) page=$1; shift;; esac case "$1" in ([0-9]) page=$1; shift;; esac
test ! -r "$1" && echo "Usage: sign [page] <document.pdf> [hoffset (-160) [voffset (-310) [scale [signature-image]]]]" && exit 1 test ! -r "$1" && echo "Usage: sign [page] <document.pdf> [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 tmp_base=/tmp/sign
mkdir -p $tmp_base 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_signed=$tmp_base/$1_last-signature.pdf
tmp_reversed=$tmp_base/$1_reverse.pdf tmp_reversed=$tmp_base/$1_reverse.pdf
sig=$tmp_base/signature_offset.pdf sig=$tmp_base/signature_offset.pdf

View File

@ -2,6 +2,7 @@
# https://stackoverflow.com/questions/4842424/list-of-ansi-color-escape-sequences/33206814#33206814 # https://stackoverflow.com/questions/4842424/list-of-ansi-color-escape-sequences/33206814#33206814
print("\\033[XXm") print("\\033[XXm")
print("-- Use Ctrl-V ESC if not using printf")
for i in range(30,37+1): for i in range(30,37+1):
print("\033[%dm%d\t\t\033[%dm%d" % (i,i,i+30,i+30)); print("\033[%dm%d\t\t\033[%dm%d" % (i,i,i+30,i+30));
@ -22,16 +23,13 @@ print(" ")
def illustrate(command, *text): def illustrate(command, *text):
print("\033[", command, "m\\033[", command, "m - ", *text, sep="", end="\t") 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, text, " on")
illustrate(command + 20, text, " off\033[0m") illustrate(command + add, text, " off\033[0m")
print() print()
toggle(1, "Bold") toggle(1, "Bold", 21)
toggle(2, "Grey") toggle(2, "Grey")
toggle(3, "Italic") toggle(3, "Italic")
toggle(4, "Underline") toggle(4, "Underline")
#toggle(5, "Bold")
#toggle(6, "Bold")
toggle(7, "Highlight") toggle(7, "Highlight")
#toggle(8, "Bold")
toggle(9, "Strike") toggle(9, "Strike")

View File

@ -6,4 +6,4 @@
# If first arg is a digit, it displaces the default depth of 3 # 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 # Any other arguments (usually pathnames) are passed on to the tree command
case "$1" in ([0-9]) depth=$1; shift;; esac 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

3
.local/bin/scripts/unlock Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
# Unlock failed logins for user
faillock --user ${USER:-$1} --reset