ambevar-dotfiles/.scripts/vcsclean

46 lines
882 B
Bash
Executable File

#!/bin/sh
if [ $# -eq 0 ] || [ "$1" = "-h" ]; then
cat <<EOF
Usage: ${0##*/} [FOLDER]
Clean current folder from all VCS control folders recursively.
EOF
exit
fi
if [ -z "$1" ]; then
WORKDIR="$PWD"
else
WORKDIR="$1"
fi
unset CHOICE
echo -n "Clean VCS control folders? [y/N] "
read CHOICE
CHOICE=$(echo $CHOICE | tr '[:upper:]' '[:lower:]')
if [ "$CHOICE" = "y" ]; then
## First clean the folders.
find "$WORKDIR" \( \
-path "*/.git/*" -o \
-path "*/.bzr/*" -o \
-path "*/.cvs/*" -o \
-path "*/.hg/*" -o \
-path "*/.svn/*" \) \
-delete
## Remove the empty vcs folder.
find "$WORKDIR" -type d \( \
-name ".bzr" -o \
-name ".cvs" -o \
-name ".git" -o \
-name ".hg" -o \
-name ".svn" \) \
-delete
echo "VCS files cleaned."
fi