Created
June 13, 2010 11:17
-
-
Save netj/436581 to your computer and use it in GitHub Desktop.
Mark empty dirs in a git repo with .gitignore files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# git-mark-empty-dirs -- Mark empty dirs in a git repo with .gitignore files | |
# Author: Jaeho Shin <[email protected]> | |
# Created: 2009-12-03 | |
set -e | |
remove-or-mark() { | |
local d=$1; shift | |
interact() { | |
echo "Found empty dir: \`$d'" | |
echo " (R)emove all empty parents" | |
echo " (r)emove only itself" | |
echo " (m)ark with .gitignore" | |
echo " (s)kip" | |
echo " (q)uit" | |
read -n1 -p"Choose action [Rrmsq]: " r | |
echo | |
case "$r" in | |
r) rmdir "$d" ;; | |
R) rmdir -p "$d" || true ;; | |
m) touch "$d"/.gitignore ;; | |
s) ;; | |
q) break ;; | |
*) interact ;; | |
esac | |
} | |
interact | |
} | |
# find empty dirs and remove or mark | |
{ | |
find "$@" -type d | | |
while read d | |
do [ -n "`ls -A "$d"`" ] || remove-or-mark "$d" 0<&3 | |
done | |
} 3<&0- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment