From 695a31f19e746b173adf231c9c9fc5ca2676587a Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Thu, 9 Dec 2021 12:27:33 +0100 Subject: [PATCH] bin: improve empty folder deletion --- .local/bin/scripts/clean | 4 ++-- .local/bin/scripts/rd | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.local/bin/scripts/clean b/.local/bin/scripts/clean index 9f17152..7d1df84 100755 --- a/.local/bin/scripts/clean +++ b/.local/bin/scripts/clean @@ -18,10 +18,10 @@ for f in ${_clean_folders[@]} do "$local" >/dev/null 2>&1 && f="$(echo "$f" | sed "s|$HOME|$($loc)|")" test -f $f || test -d $f && echo $f && rm -rf $i $f done -find "$dir" -maxdepth 2 -not -name ".stfolder" -empty -exec rm -vd {} + +find "$dir" -maxdepth 2 -not -name ".stfolder" -empty -printf "Removing empty %p\n" -delete highlight "e to recursively remove empty folders and files" -[[ $1 =~ "e" ]] && find -empty -type d -exec rm -vd {} + +[[ $1 =~ "e" ]] && find -empty -not -name ".stfolder" -empty -printf "Removing empty %p\n" -delete for k in "${!_clean_map[@]}"; do folder="${_clean_map[$k]}" diff --git a/.local/bin/scripts/rd b/.local/bin/scripts/rd index bc55e3e..a0cba94 100755 --- a/.local/bin/scripts/rd +++ b/.local/bin/scripts/rd @@ -10,7 +10,7 @@ do read answer test "$answer" = "y" && $elevate rm -rf "$f" - else find "$f" -maxdepth 4 -empty -printf "Removing empty %p\n" -delete + else find "$f" -maxdepth 4 -not -name ".stfolder" -empty -printf "Removing empty %p\n" -delete test -e "$f" && echo -n "$f ($(ls -A $f | head -3 | paste -s -d' ')) " >&2 && $elevate rm -rI "$f"