[file_utils] mvparent: allow multiple arguments

This commit is contained in:
Matteo Cypriani 2014-06-01 20:38:55 -04:00
parent 83e5bfddeb
commit e382dace97
1 changed files with 27 additions and 17 deletions

View File

@ -10,29 +10,39 @@
# #
# Moves the contents of the given directory into its parent directory. # Moves the contents of the given directory into its parent directory.
if [ $# -ne 1 -o ! -d "$1" ] ; then if [ $# -lt 1 ] ; then
echo "Usage: `basename $0` DIRECTORY" >&2 echo "Usage: `basename $0` DIRECTORY [DIRECTORY [...]]" >&2
exit 1 exit 1
fi fi
rep=$(dirname "$1") while [ "$1" != "" ] ; do
cible=$(basename "$1") REP="$1"
shift
if [ "$cible" = "." -o "$cible" = ".." ] ; then if [ ! -d "$REP" ] ; then
echo "Warning! \"$REP\" is not a directory: ignoring." >&2
continue
fi
TARGET=$(basename "$REP")
REP=$(dirname "$REP")
if [ "$TARGET" = "." -o "$TARGET" = ".." ] ; then
echo "Target cannot end by « . » or « .. »!" >&2 echo "Target cannot end by « . » or « .. »!" >&2
exit 2 exit 2
fi fi
echo "Move the contents of « $rep/$cible » into « $rep »…" >&2 echo "Moving the contents of « $REP/$TARGET » into « $REP »..." >&2
cd "$rep" cd "$REP"
if [ "$(echo "$cible"/*)" != "$cible/*" ] ; then if [ "$(echo "$TARGET"/*)" != "$TARGET/*" ] ; then
mv "$cible"/* . mv "$TARGET"/* .
fi fi
if [ "$(echo "$cible"/.[!.]*)" != "$cible/.[!.]*" ] ; then if [ "$(echo "$TARGET"/.[!.]*)" != "$TARGET/.[!.]*" ] ; then
mv "$cible"/.[!.]* . mv "$TARGET"/.[!.]* .
fi fi
rmdir "$cible" rmdir "$TARGET"
done