2022-01-05 16:53:06 +00:00
|
|
|
#!/bin/sh -e
|
2021-09-16 12:18:26 +00:00
|
|
|
# Remove recursively safely
|
2021-11-09 04:37:07 +00:00
|
|
|
case "$1" in ([0-9]) depth=$1; shift;; esac
|
2022-03-15 15:56:22 +00:00
|
|
|
for f in "${@:-$PWD}"
|
2021-09-16 12:18:26 +00:00
|
|
|
do
|
2022-01-25 12:55:23 +00:00
|
|
|
test -w "$(dirname "$f")" && elevate="" || elevate=sudo
|
2022-01-05 16:53:06 +00:00
|
|
|
if test -d "$f"
|
2022-01-07 12:18:35 +00:00
|
|
|
then
|
2021-09-16 12:18:26 +00:00
|
|
|
if test -e "$f/.git" || test -e "$f/packed-refs"
|
2022-01-05 16:53:06 +00:00
|
|
|
then echo -n "Force delete git project $f? "
|
|
|
|
read answer
|
|
|
|
test "$answer" = "y" &&
|
2022-04-11 11:48:12 +00:00
|
|
|
$elevate rm -rf "$f" &&
|
2022-05-10 07:25:01 +00:00
|
|
|
continue
|
2022-04-11 11:48:12 +00:00
|
|
|
fi
|
|
|
|
|
2024-01-12 16:53:41 +00:00
|
|
|
# Clean empty files
|
|
|
|
$elevate find -name '.thumbnails' -printf 'Pre-cleaning %p\n' -exec rm -r {} +
|
2024-02-20 18:54:51 +00:00
|
|
|
$elevate find -H "$f" -maxdepth $(expr 1 \& "$f" = "/" \| 5 \& $# \> 0 \| 3) \
|
|
|
|
\( -name '.stfolder' -o -name '.*keep' -o -name '*.py' -o -name 'nodelay.txt' -o -name '.git' -o -name 'tmp' -o -name '.nomedia' -o -name '__init__.py' -o -name '*ignore' -o -name 'instalee' \) \
|
|
|
|
\( -type d -o -type f \) -prune -o -empty -printf 'Removing empty %p\n' -exec rm -d {} +
|
2022-12-13 12:25:04 +00:00
|
|
|
# $elevate find -H "$f" -maxdepth $(expr 1 \& "$f" = "/" \| 5 \& $# \> 0 \| 4) -type d -empty -name .stfolder -exec rm -div {} \;
|
2022-04-11 11:48:12 +00:00
|
|
|
test $# -eq 0 && exit $?
|
|
|
|
if test -e "$f"; then
|
|
|
|
echo -n "$f ($(ls -A "$f" | head -3 | paste -s -d' ')) " >&2 &&
|
|
|
|
$elevate rm -rI "$f"
|
2021-09-16 12:18:26 +00:00
|
|
|
fi
|
2022-01-05 16:53:06 +00:00
|
|
|
else $elevate rm -i "$f"
|
2021-09-16 12:18:26 +00:00
|
|
|
fi
|
|
|
|
done
|