#!/bin/bash
# Set the .gitignore file in each subdirectory of a git working directory,
# such that ucampas-generated HTML files are ignored by "git status".
# If there are any files (one per line) listed in
# a file called .ugitignore in the respective directory, then add these
# as well. Only *-b.html files that exist in the index will be processed.
for d in  . `find * -type d` ; do (
  if [ `git ls-files "$d" | wc -l` != '0' ] ; then
    cd "$d" || exit
    shopt -s nullglob
    file=.gitignore
    rm -f $file
    for src in *-b.html ; do
      if [ -n "`git ls-files "$src"`" ] ; then
        echo "${src%-b.html}.html" >>$file
      fi
    done
    for src in *-b.php ; do
      if [ -n "`git ls-files "$src"`" ] ; then
        echo "${src%-b.php}.php" >>$file
      fi
    done
    [ -r .ugitignore ] && cat .ugitignore >>$file
    pwd
  fi
) ; done
