Skip to content

Instantly share code, notes, and snippets.

@netj
Created June 13, 2010 11:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save netj/436581 to your computer and use it in GitHub Desktop.
Save netj/436581 to your computer and use it in GitHub Desktop.
Mark empty dirs in a git repo with .gitignore files
#!/usr/bin/env bash
# git-mark-empty-dirs -- Mark empty dirs in a git repo with .gitignore files
# Author: Jaeho Shin <netj@sparcs.org>
# 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