dotfiles/.local/bin/scripts/rd

18 lines
478 B
Bash
Executable File

#!/bin/sh
# Remove recursively safely
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 find "$f" -maxdepth 4 -type d -empty -printf "Removing empty %p\n" -delete
test -e "$f" && echo -n "$f " >&2 && $elevate rm -rI "$f"
fi
else $elevate rm -i "$f"
fi
shift
done