#!/bin/sh
# http://www.berklix.com/~jhs/bin/.sh/nolower
# bourne shell script by Julian H. Stacey
# See Also (and run after or before some of these in):    ~/bin/.sh/
#       nobracket nocolon nolower noquote nospace noupper
#	Run nospace Before noupper Or nolower Or nocolon
#	JJLATER Decide Priority Of nobracket And noquote And nospace
# Suggestion: first run noquote then run nolower

# Moves all files to upper case filenames 
# Syntax	nolower filename[s]

# Warning:
#	Only converts last bit of path to upper case eg
#		DIRECTORY/FILE to DIRECTORY/file
#	So if you want to convert a whole tree use:
#		find . -depth -name \*\[a-z\]\* -exec  ~/bin/.sh/nolower {} \;

for i in $*
do
	if [ "$i" != "`basename $i | tr "[:lower:]" "[:upper:]"`" ]; then
		# echo "Already upper case, no need to convert."
	# else
		# For trees called from find,
		# Need to progressively operate just on basename
		#	dirname  ./a.b.c/d.e.f/g.h.i	# ./a.b.c/d.e.f
		# 	basename ./a.b.c/d.e.f/g.h.i	# g.h.i
		#	dirname  ./a.b.c/d.e.f      	# ./a.b.c
		# 	basename ./a.b.c/d.e.f      	# d.e.f
		#	dirname  ./a.b.c		# .
		#	dirname    a.b.c		# .
		#	dirname    a			# .
		#	basename ./a.b.c		# a.b.c
		old=`basename $i`
		new=`echo $old | tr "[:lower:]" "[:upper:]"`
		dir=`dirname $i`
		mv $dir/$old    $dir/${new}X
		mv $dir/${new}X $dir/${new}
		# Notes on 'X'
		#	Above without the X used to fail (on 9.3-RELEASE) on
		#	file systems mounted as msdosfs
		#	(which maps one case to another)
		#	(as 'mkdir DUMMY;mv DUMMY dummy' also fails with:
		#	mv: rename DUMMY to dummy/DUMMY: Invalid argument
		#	See man mount_msdosfs
		#       X is at right end of path name not left,
		#	because although X at either end works for files just
		#	in current directory, it breaks if find provides
		#	deep paths eg:
		#		 mv: X./tech/bafug/amd64/bafug2-Peter-3.mov: \
		#		 No such file or directory
		#	I use X not .X in case a DOS FS may not like a
		#	double dot as in prog_ram.c.X
	fi
shift
done
