# recursing contracter.
### Copyright 1999 Rick Hohensee
## This file is released for redistribution only as part of
## an intact entire cLIeNUX Core.

## recursion, dude. That's almost like, like Real Programming(tm) ain't it?

if test $# == 0
then
	echo "
	contract is a script. It removes a directory name, but not it's
	contents, by pulling all it's contents up into the parent directory.
	contract assumes the current working directory is the parent dir of
	the subdirectory to be contracted.
	

	USAGE:    cd directory ;  contract  subdirectory

	"
exit
fi


function thisdir {
for F in * 			## for cwd/*
do 	
	if [ -d "../$F" ] && [ -d $F ]  	# if dirname/dirname conflict
	then	{				# can't just mv the dir and
		pushd $F			# we want to merge same-names
		thisdir 			# recurse
##		popd
		rmdir $F
		}
	elif [  -e "../$F" ]  			# non-dir/dir conflict 
	then	{ mv $F ../$F.contracted
		}
	elif [ -e $F ] 				# no conflict
	then	{ mv $F ../
		}
	fi
	## at this point we've either mv'ed or rm'ed this node's contents

done
TRAILER=`pwd`	
popd
rmdir $TRAILER
}


pushd $1		## work from cwd = source dir. rm it in function.
thisdir


