[file_utils] mvparent: allow multiple arguments
This commit is contained in:
parent
83e5bfddeb
commit
e382dace97
|
@ -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 "Target cannot end by « . » or « .. »!" >&2
|
echo "Warning! \"$REP\" is not a directory: ignoring." >&2
|
||||||
exit 2
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Move the contents of « $rep/$cible » into « $rep »…" >&2
|
TARGET=$(basename "$REP")
|
||||||
|
REP=$(dirname "$REP")
|
||||||
|
|
||||||
cd "$rep"
|
if [ "$TARGET" = "." -o "$TARGET" = ".." ] ; then
|
||||||
|
echo "Target cannot end by « . » or « .. »!" >&2
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$(echo "$cible"/*)" != "$cible/*" ] ; then
|
echo "Moving the contents of « $REP/$TARGET » into « $REP »..." >&2
|
||||||
mv "$cible"/* .
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$(echo "$cible"/.[!.]*)" != "$cible/.[!.]*" ] ; then
|
cd "$REP"
|
||||||
mv "$cible"/.[!.]* .
|
|
||||||
fi
|
|
||||||
|
|
||||||
rmdir "$cible"
|
if [ "$(echo "$TARGET"/*)" != "$TARGET/*" ] ; then
|
||||||
|
mv "$TARGET"/* .
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$(echo "$TARGET"/.[!.]*)" != "$TARGET/.[!.]*" ] ; then
|
||||||
|
mv "$TARGET"/.[!.]* .
|
||||||
|
fi
|
||||||
|
|
||||||
|
rmdir "$TARGET"
|
||||||
|
done
|
||||||
|
|
Loading…
Reference in New Issue