bin: new scripts

This commit is contained in:
xeruf 2023-11-04 19:08:39 +01:00
parent dc9cee6da5
commit 863ef2051b
16 changed files with 44 additions and 15 deletions

View File

@ -1,5 +1,6 @@
#!/bin/sh #!/bin/sh
# Write a CACHEDIR.TAG to mark this or the given directory as cache.
echo 'Signature: 8a477f597d28d172789f06886806bc55 echo 'Signature: 8a477f597d28d172789f06886806bc55
# This file is a cache directory tag created by (application name). # This file is a cache directory tag created by (application name).
# For information about cache directory tags, see: # For information about cache directory tags, see:
# https://bford.info/cachedir/'>CACHEDIR.TAG # https://bford.info/cachedir/' > "${1:-.}/CACHEDIR.TAG"

View File

@ -1,3 +1,4 @@
#!/bin/sh #!/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 {} + case "$1" in ([0-9]) depth=$1; shift;; esac
find -maxdepth ${depth:-4} \( -name "*.sh" -o -name "*.py" -o -path '*/githooks/*' \) "$@" -exec chmod -v +x {} +

View File

@ -5,7 +5,8 @@
typeset -A _clean_map typeset -A _clean_map
_clean_map=([h]=$XDG_CACHE_HOME [t]=/var/tmp [l]=/var/log [v]=/var/cache) _clean_map=([h]=$XDG_CACHE_HOME [t]=/var/tmp [l]=/var/log [v]=/var/cache)
# TODO .mix - outdated version in socha # TODO .mix - outdated version in socha
_clean_home=(.ant .autopsy .bundle .cache .cargo .cpanm .docker .stack .hex .nix-defexpr .parallel .surf _clean_home=(.ant .autopsy .bundle .cargo .cpanm .docker .stack .hex .nix-defexpr .parallel .surf
#.cache
.yarn .node_modules .npm .pnpm-store .node-gyp .nv .electron .electron-gyp .yarn .node_modules .npm .pnpm-store .node-gyp .nv .electron .electron-gyp
.gradle .gradle-kotlin-dsl .java .kscript .konan .m2 .openjfx .gradle .gradle-kotlin-dsl .java .kscript .konan .m2 .openjfx
.log luametatex-cache luatex-cache .texlive .log luametatex-cache luatex-cache .texlive

View File

@ -15,8 +15,8 @@ if ! test "$command"; then
(image/*) command="exiftool";; (image/*) command="exiftool";;
(*sqlite*) sqldiff --summary "${files[@]}" | grep -v '0 changes, 0 inserts, 0 deletes';; # TODO syntax highlighting for INSERT/UPDATE/DELETE (*sqlite*) sqldiff --summary "${files[@]}" | grep -v '0 changes, 0 inserts, 0 deletes';; # TODO syntax highlighting for INSERT/UPDATE/DELETE
(text/*) (text/*)
# Use wiked-diff only for text <10MB # Use wiked-diff only for text <100KB
if test 10000000 -gt "$(stat --format=%s "${files[@]}" | paste -s -d'+' | bc)" if test 100000 -gt "$(stat --format=%s "${files[@]}" | paste -s -d'+' | bc)"
then wiked-diff "${files[@]}" then wiked-diff "${files[@]}"
else diff --color=always --unified=1 --report-identical-files "${files[@]}" else diff --color=always --unified=1 --report-identical-files "${files[@]}"
fi;; fi;;

View File

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
# Troubleshoot.sh # troubleshoot disk issues and log results
# A more elaborate version of Troubleshoot.sh. # A more elaborate version of Troubleshoot.sh.
SUCCESS=0 SUCCESS=0
@ -32,4 +32,5 @@ do
smartctl -i -A $e >> ${date}_Troubleshoot.log # Run smartctl on all disks smartctl -i -A $e >> ${date}_Troubleshoot.log # Run smartctl on all disks
fi fi
done done
exit $? # In this case, exit code = 99, since that is function return. exit $? # In this case, exit code = 99, since that is function return.

View File

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
# Find config files with fzf, preview and edit them # Find config files with fzf, preview and edit them
# Common config files are automatically checked/reloaded # Common config files are automatically checked/reloaded
alias dedup='awk '"'"'!a[$0]++'"'" alias dedup-lines='awk '"'"'!a[$0]++'"'"
listconf() { listconf() {
{ cat "$conf_cache" { cat "$conf_cache"
@ -12,7 +12,7 @@ listconf() {
\( -name Partitions -o -name mdn -o -name .git -o -name .local -o -name plugged \) -prune -o \ \( -name Partitions -o -name mdn -o -name .git -o -name .local -o -name plugged \) -prune -o \
! \( -iname "*.markdown" -o -iname "*.md" -o -name "Network Persistent State" -o -iname "*.pem" \) -a \ ! \( -iname "*.markdown" -o -iname "*.md" -o -name "Network Persistent State" -o -iname "*.pem" \) -a \
-type f -readable -exec grep -lI '' {} + 2>/dev/null -type f -readable -exec grep -lI '' {} + 2>/dev/null
} | dedup } | dedup-lines
} }
conf_cache_dir="${XDG_CACHE_HOME:-$HOME/.cache}/$(basename "$0")" conf_cache_dir="${XDG_CACHE_HOME:-$HOME/.cache}/$(basename "$0")"

6
.local/bin/scripts/grtag Executable file
View File

@ -0,0 +1,6 @@
#!/bin/sh
# Rescursively find org-mode and other tags
tag=$1
shift
grep --color=always --line-number --binary-files=without-match --directories=recurse --exclude-dir logseq --ignore-case ":$tag:
@$tag\b" "$@"

View File

@ -26,13 +26,15 @@ showinfo() {
cmd="$1" cmd="$1"
case "$cmd" in case "$cmd" in
(fwupdmgr|hunt|rdoc|gh|chordpro|bat|pdfjam|reflector|topgrade|r128gain|7z|kubectl|diffr|docker|jrnl|difft|wiked-diff|qpdf|ninja) unbuffer "$@" --help | sed 's|^[^ ].*:|\0|' | $paginate;; (fwupdmgr|hunt|rdoc|gh|chordpro|bat|pdfjam|reflector|topgrade|r128gain|7z|kubectl|diffr|docker|jrnl|difft|wiked-diff|qpdf|ninja)
unbuffer "$@" --help | sed 's|^[^ ].*:|\0|' | $paginate;;
(caddy|stretchly|go|flutter) (caddy|stretchly|go|flutter)
shift shift
"$cmd" help "$@" | $paginate;; "$cmd" help "$@" | $paginate;;
(doom|sgpt) "$@" --help;; # Paginates itself (doom|sgpt) "$@" --help;; # Paginates itself
(mpw) "$@" -h 2>&1 | $paginate;; (rsgain) "$@" custom --help;;
(spectre|plantuml|java) unbuffer "$@" -help | $paginate;; (spectre|plantuml|java) unbuffer "$@" -help | $paginate;;
(mpw) "$@" -h 2>&1 | $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

@ -1,5 +1,5 @@
#!/bin/sh -e #!/bin/sh -e
# Displays the latest files in the given directory or pwd # Lists the latest modified files in the given directory or pwd
test "$1" = "-a" && all=true && shift test "$1" = "-a" && all=true && shift
for f in "${@:-$PWD}" for f in "${@:-$PWD}"
do test $# -gt 1 && highlight "$f" do test $# -gt 1 && highlight "$f"

View File

@ -1,12 +1,15 @@
#!/bin/sh -e #!/bin/sh -e
# Add the modification date in front of the filename # Add the modification date in front of the filename
test $# -eq 0 && echo "predate [-s] [newname] <files...>" && exit 2
IFS='\n' IFS='\n'
test "$1" = -s && short=true && shift test "$1" = -s && short=true && shift
# Whether to change the filename suffix after the date
test ! -f "$1" && rename=true && name=$1 && shift || rename=false test ! -f "$1" && rename=true && name=$1 && shift || rename=false
for file for file
do mv --verbose --interactive "$file" \ do mv --verbose --interactive "$file" \
"$(latest "$file" | head -2 | tail -1 | "$(latest "$file" | head -2 | tail -1 |
cut -c$(test "$short" && echo "3,4,6,7,9,10" || echo "-10"))$( cut -c$(test "$short" && echo "3,4,6,7,9,10" || echo "-10"))$(
if $rename if $rename
then echo "$(test "$name" && echo "_$name").${file##*.}" then echo "$(test "$name" && echo "_$name").${file##*.}"
else echo "_$file" | sed 's/^_2\?\([0-9]\{2,3\}\)-\([0-9]\{2\}\)\(-[0-9]\{2\}\)\?_\?/_/' else echo "_$file" | sed 's/^_2\?\([0-9]\{2,3\}\)-\([0-9]\{2\}\)\(-[0-9]\{2\}\)\?_\?/_/'

View File

@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
# Execute a gradle task (default test) until it fails # Execute a gradle task (by default "test") until it fails
code=0 code=0
case "$1" in ([0-9]*) code=$1; shift;; esac case "$1" in ([0-9]*) code=$1; shift;; esac

View File

@ -1,3 +1,6 @@
#!/bin/sh #!/bin/sh
# Recursively add replaygain to the given files or from the current directory # Recursively add replaygain to the given files or from the current directory
r128gain $(test -f "$1" || echo '--recursive') --skip-tagged --preserve-times 1 "${@:-.}" r128gain $(test -f "$1" || echo '--recursive') --skip-tagged --preserve-times 1 "${@:-.}"
# rsgain custom --album --skip-existing --tagmode=i
# Need a find command, call for each album
# rsgain easy --skip-existing --multithread=${SPARE_CORES:-3} "${@:-.}"

View File

@ -2,4 +2,4 @@
# Rename files according to a given extended regex sed expression # Rename files according to a given extended regex sed expression
sedexpr="$1" sedexpr="$1"
shift shift
find "$@" -exec sh -c 'mv -iv "{}" "$(echo "{}" | sed -E "'$sedexpr'")" 2>/dev/null' \; find "$@" -exec sh -c 'mv -iv "{}" "$(echo "{}" | sed -E "'"$sedexpr"'")" 2>/dev/null' \;

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

@ -0,0 +1,3 @@
#!/bin/sh
mkdir -p $(dirname $1)
touch "$@"

5
.local/bin/scripts/vmpasswd Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh -ex
# Generate a cloud-init hashed password for the given machine and copy it
passwd=$(mkpasswd --method=SHA-512 --rounds=4096 $(pass mpw -t basic "$@"))
echo $passwd
echo $passwd | wl-copy

View File

@ -2,6 +2,9 @@
# xdg-open all given files # xdg-open all given files
# TODO handle .desktop-files with gtk-launch/dex/kioclient exec, add selector from xdg-mime-file # TODO handle .desktop-files with gtk-launch/dex/kioclient exec, add selector from xdg-mime-file
while test $# -gt 0; do while test $# -gt 0; do
xdg-open "$(case "$1" in (-*) echo './';; esac)$1" case $1 in
(*.epub) okular "$1" &;;
(*) xdg-open "$(case "$1" in (-*) echo './';; esac)$1";;
esac
shift shift
done done