2010-01-06 22:18:18 +01:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# mvparent.sh, Copyright © 2007, 2010 Matteo Cypriani
|
|
|
|
#
|
|
|
|
# This program is free software. It comes without any warranty, to
|
|
|
|
# the extent permitted by applicable law. You can redistribute it
|
|
|
|
# and/or modify it under the terms of the Do What The Fuck You Want
|
|
|
|
# To Public License, Version 2, as published by Sam Hocevar. See
|
|
|
|
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
|
|
|
#
|
|
|
|
# Moves the contents of the given directory into its parent directory.
|
|
|
|
|
2014-06-02 02:38:55 +02:00
|
|
|
if [ $# -lt 1 ] ; then
|
|
|
|
echo "Usage: `basename $0` DIRECTORY [DIRECTORY [...]]" >&2
|
2010-01-06 22:18:18 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2014-06-02 02:38:55 +02:00
|
|
|
while [ "$1" != "" ] ; do
|
|
|
|
REP="$1"
|
|
|
|
shift
|
2010-01-06 22:18:18 +01:00
|
|
|
|
2014-06-02 02:38:55 +02:00
|
|
|
if [ ! -d "$REP" ] ; then
|
|
|
|
echo "Warning! \"$REP\" is not a directory: ignoring." >&2
|
|
|
|
continue
|
|
|
|
fi
|
2010-01-06 22:18:18 +01:00
|
|
|
|
2014-06-02 02:38:55 +02:00
|
|
|
TARGET=$(basename "$REP")
|
|
|
|
REP=$(dirname "$REP")
|
2010-01-06 22:18:18 +01:00
|
|
|
|
2014-06-02 02:38:55 +02:00
|
|
|
if [ "$TARGET" = "." -o "$TARGET" = ".." ] ; then
|
|
|
|
echo "Target cannot end by « . » or « .. »!" >&2
|
|
|
|
exit 2
|
|
|
|
fi
|
2012-10-01 15:31:56 +02:00
|
|
|
|
2014-06-02 02:38:55 +02:00
|
|
|
echo "Moving the contents of « $REP/$TARGET » into « $REP »..." >&2
|
2012-10-01 15:31:56 +02:00
|
|
|
|
2014-06-02 02:38:55 +02:00
|
|
|
cd "$REP"
|
|
|
|
|
|
|
|
if [ "$(echo "$TARGET"/*)" != "$TARGET/*" ] ; then
|
2016-01-22 14:53:52 +01:00
|
|
|
mv -n "$TARGET"/* .
|
2014-06-02 02:38:55 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$(echo "$TARGET"/.[!.]*)" != "$TARGET/.[!.]*" ] ; then
|
2016-01-22 14:53:52 +01:00
|
|
|
mv -n "$TARGET"/.[!.]* .
|
2014-06-02 02:38:55 +02:00
|
|
|
fi
|
2012-10-01 15:31:56 +02:00
|
|
|
|
2014-06-02 02:38:55 +02:00
|
|
|
rmdir "$TARGET"
|
|
|
|
done
|