dotfiles/.local/bin/scripts/rd

19 lines
522 B
Plaintext
Raw Normal View History

#!/bin/sh
# Remove recursively safely
2021-11-09 04:37:07 +00:00
case "$1" in ([0-9]) depth=$1; shift;; esac
for f in "$@"
do
2021-10-04 08:46:40 +00:00
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
2021-10-04 08:46:40 +00:00
test "$answer" = "y" && $elevate rm -rf "$f"
2021-10-22 12:14:25 +00:00
else find "$f" -maxdepth 4 -type d -empty -printf "Removing empty %p\n" -delete
2021-10-04 08:46:40 +00:00
test -e "$f" && echo -n "$f " >&2 && $elevate rm -rI "$f"
fi
2021-10-04 08:46:40 +00:00
else $elevate rm -i "$f"
fi
shift
done