25 lines
639 B
Bash
Executable File
25 lines
639 B
Bash
Executable File
#!/bin/sh -e
|
|
# Remove recursively safely
|
|
case "$1" in ([0-9]) depth=$1; shift;; esac
|
|
for f in "${@-.}"
|
|
do
|
|
test -w "$f" && elevate="" || elevate=sudo
|
|
if test -d "$f"
|
|
then
|
|
if test -e "$f/.git" || test -e "$f/packed-refs"
|
|
then echo -n "Force delete git project $f? "
|
|
read answer
|
|
test "$answer" = "y" &&
|
|
$elevate rm -rf "$f"
|
|
else
|
|
$elevate find "$f" -maxdepth 4 -not -name ".stfolder" -empty -printf "Removing empty %p\n" -delete
|
|
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"
|
|
fi
|
|
fi
|
|
else $elevate rm -i "$f"
|
|
fi
|
|
done
|