From b1404b35c2e20fc159aab78d0044cba2d048c4fa Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Wed, 9 Nov 2022 12:45:38 +0100 Subject: [PATCH] bin: improve find matching --- .config/shell/music | 8 ++++---- .local/bin/scripts/b | 4 ++-- .local/bin/scripts/clean | 5 +++-- .local/bin/scripts/update-e2b | 4 ++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/.config/shell/music b/.config/shell/music index 0e2d97d..5254a1a 100644 --- a/.config/shell/music +++ b/.config/shell/music @@ -5,7 +5,7 @@ alias scbra='scpr zebra "/srv/funkwhale/data/music${PWD/$MUSIC}"' findsongs() { find -regextype posix-extended -maxdepth 1 -type f \ - -regex "${1:-.*\.(mp3|flac|wav|m4a)}" -printf "%P\n" + -iregex "${1:-.*\.(mp3|flac|wav|m4a)}" -printf "%P\n" } addtopl() { @@ -44,13 +44,13 @@ addsong() { addalbum() { mkdir -p "$MUSIC/$1" mkdir -p "$MUSIC_RAW/$1" - f1 -regextype posix-extended -type f -regex "\./(cover|folder)\.(png|jpg|jpeg)" | + f1 -regextype posix-extended -type f -iregex "\./(cover|folder)\.(png|jpg|jpeg)" | while read cover; do foundcover="true" cp -v "$cover" "$MUSIC/$1" && mv -v "$cover" "$MUSIC_RAW/$1" done - test "$foundcover" || f1 -regextype posix-extended -type f -regex ".*\.(png|jpg|jpeg)" | + test "$foundcover" || f1 -regextype posix-extended -type f -iregex ".*\.(png|jpg|jpeg)" | while read cover; do cp -v "$cover" "$MUSIC/$1" && mv -v "$cover" "$MUSIC_RAW/$1" @@ -72,7 +72,7 @@ formatsongs() { done ) # fd --no-ignore-vcs --type f --extension opus --exec opusdec --quiet "{}" "{.}.wav" \; ".*" "$@" - find "$@" -type f -name "*.wav" -exec sh -c ' + find "$@" -type f -iname "*.wav" -exec sh -c ' f="{}" && echo "Converting $f to ${f%.*}.flac" && ffmpeg -i "$f" "${f%.*}.flac" -v warning && diff --git a/.local/bin/scripts/b b/.local/bin/scripts/b index 554bee9..3a8d3ba 100755 --- a/.local/bin/scripts/b +++ b/.local/bin/scripts/b @@ -37,7 +37,7 @@ fileinfo() { for arg do case "$arg" in (-*) continue;; esac $elevate file --exclude elf -E "$arg" - $elevate ssh-keygen -l -f "$arg" 2>/dev/null + $elevate ssh-keygen -l -f "$arg" 2>/dev/null || true # TODO do not grep bitrate but extract properly #probe="$($elevate ffprobe "$arg" 2>&1)" #echo $probe | grep -v -e '00:00:00.04' -e 'ansi' && @@ -101,7 +101,7 @@ for arg; do ;; (*) case "$(file --dereference "$arg")" in - (*\ ?udio*) + (*\ ?udio*|*\ ADTS,*) # TODO preconvert aac - |*\ ADTS\ * if ! $inspect && which audiowaveform >/dev/null; then img="$tmpfile.png" diff --git a/.local/bin/scripts/clean b/.local/bin/scripts/clean index 13be803..6cc1c95 100755 --- a/.local/bin/scripts/clean +++ b/.local/bin/scripts/clean @@ -46,13 +46,14 @@ highlight "s :: recursively remove logs" highlight "m :: recursively remove mac-files" if [[ $1 =~ "m" ]]; then find -name '__MACOSX' -print -exec rm -r {} + - find -iname '.spotlight*' -print -exec rm -rI {} + + find \( -iname '.spotlight*' -o -name 'System Volume Information' -o -name '.fseventsd' \) -print -exec rm -rI {} + find -name '*.DS_Store' -delete fi highlight "d :: recursively remove development caches" if [[ $1 =~ "d" ]]; then - find -maxdepth 1 \( -name "*.aux" -o -name "*.log" -o -name "*.t[uo]c" -o -name "*.out" \) -print -delete + # TODO some matches duplicate log clearing + find -maxdepth 1 \( -name "*.aux" -o -name "*.log" -o -name "*.t[uo][ca]" -o -name "*.out" \) -print -delete find \( -name 'src' -o -name 'vendor' \) -prune -o \ -type d \( -name 'cache' $(echo $DIRS_GENERATED | sed 's|-x \([^ ]\+\)|-o -name \1|g') \) \ -print -exec rm $i -r {} + -prune diff --git a/.local/bin/scripts/update-e2b b/.local/bin/scripts/update-e2b index e515ca8..b520d1d 100755 --- a/.local/bin/scripts/update-e2b +++ b/.local/bin/scripts/update-e2b @@ -4,8 +4,8 @@ # Need to be around E2B mountpoint if it is not the default dir="$(find . "${MNT:-${XDG_RUNTIME_DIR}/mnt}" -maxdepth 3 -name _ISO -type d | grep .)" test $# -eq 0 || mv -vi "$@" "$dir/LINUX" -find "$dir" -name "*32-*.iso" -exec mv -vi {} {}def32 \; -find "$dir" -name "*.iso" -exec mv -vi {} {}def64 \; +find "$dir" -iname "*32-*.iso" -exec mv -vi {} {}def32 \; +find "$dir" -iname "*.iso" -exec mv -vi {} {}def64 \; drive=$(mount | grep "$(basename "$dir")" | cut -d' ' -f1) sudo umount $drive sudo udefrag $drive