#!/bin/bash
#########################################################
# 							#
# This is BashStyle-NG					#
#							#
# Licensed under GNU GENERAL PUBLIC LICENSE v3    	#
#							#
# Copyright 2007 - 2011 Christopher Bratusek		#
#							#
#########################################################

if [[ $WANT_DIRINFO_FLAGS == "true" ]]; then

	if [[ $1 == --help || $1 == -h ]]; then
		$MV_CMD --help
		exit 0
	elif [[ ${#} -lt "2" ]]; then
		echo "not enough arguments"
		exit 1
	fi

	destination="${!#}"

	if [[ "${destination}" == */ && ! -e "${destination}" ]]; then
		 mkdir -p "${!destination}"
	elif [[ "${destination}" == */ && -f "${destination}" ]]; then
		echo "destination already exists, but is a file."
		exit 1
	fi

	args=( "$@" )
	unset args[$#-1]
	set -- "${args[@]}"

	for path in "${args[@]}"; do
	      test "${path:0:1}" == - && MVO+="$path " && continue
	      for try in "$path" "${path%/*}" "$(dirname ${path} 2>/dev/null)"; do
		  test -e "$try"/.dirinfo || continue
		  grep -q NoMove "$try"/.dirinfo || continue
		  echo "can not move $path -- it's protected"
		  continue 2
	      done
	      $MV_CMD $MV_OPTS $MVO "$path" "$destination"
	done

	unset MVO

else	$MV_CMD "$@"
fi
