mvparent: rename variables, shellcheck
This commit is contained in:
parent
bd52bca0e2
commit
cc66a46cc1
|
@ -8,43 +8,47 @@
|
||||||
# To Public License, Version 2, as published by Sam Hocevar. See
|
# To Public License, Version 2, as published by Sam Hocevar. See
|
||||||
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||||
#
|
#
|
||||||
# Moves the contents of the given directory into its parent directory.
|
# Moves the contents of the given directory(ies) into its parent directory,
|
||||||
|
# then removes the directory(ies).
|
||||||
|
|
||||||
|
set -e
|
||||||
|
#set -x
|
||||||
|
|
||||||
if [ $# -lt 1 ] ; then
|
if [ $# -lt 1 ] ; then
|
||||||
echo "Usage: `basename $0` DIRECTORY [DIRECTORY [...]]" >&2
|
echo "Usage: $(basename "$0") DIRECTORY [DIRECTORY [...]]" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
while [ "$1" != "" ] ; do
|
while [ -n "$1" ] ; do
|
||||||
REP="$1"
|
dir="$1"
|
||||||
shift
|
shift
|
||||||
|
|
||||||
if [ ! -d "$REP" ] ; then
|
if [ ! -d "$dir" ] ; then
|
||||||
echo "Warning! \"$REP\" is not a directory: ignoring." >&2
|
echo "Warning! \"$dir\" is not a directory: ignoring." >&2
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
TARGET=$(basename "$REP")
|
target="$(basename "$dir")"
|
||||||
REP=$dirname "$REP")
|
dir="$(dirname "$dir")"
|
||||||
|
|
||||||
if [ "$TARGET" = "." -o "$TARGET" = ".." ] ; then
|
if [ "$target" = "." ] || [ "$target" = ".." ] ; then
|
||||||
echo "Target cannot end by « . » or « .. »!" >&2
|
echo "Target cannot end by « . » or « .. »!" >&2
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Moving the contents of « $REP/$TARGET » into « $REP »..." >&2
|
echo "Moving the contents of « $dir/$target » into « $dir »..." >&2
|
||||||
|
|
||||||
cd "$REP"
|
cd "$dir"
|
||||||
|
|
||||||
if [ "$(echo "$TARGET"/*)" != "$TARGET/*" ] ; then
|
if [ "$(echo "$target"/*)" != "$target/*" ] ; then
|
||||||
mv -n "$TARGET"/* .
|
mv -n "$target"/* .
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$(echo "$TARGET"/.[!.]*)" != "$TARGET/.[!.]*" ] ; then
|
if [ "$(echo "$target"/.[!.]*)" != "$target/.[!.]*" ] ; then
|
||||||
mv -n "$TARGET"/.[!.]* .
|
mv -n "$target"/.[!.]* .
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rmdir "$TARGET"
|
rmdir "$target"
|
||||||
done
|
done
|
||||||
|
|
||||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
Loading…
Reference in New Issue