mvparent: rename variables, shellcheck

This commit is contained in:
Matteo Cypriani 2018-04-11 21:09:21 +02:00
vanhempi bd52bca0e2
commit cc66a46cc1
1 muutettua tiedostoa jossa 20 lisäystä ja 16 poistoa

Näytä tiedosto

@ -8,43 +8,47 @@
# 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.
# 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
echo "Usage: `basename $0` DIRECTORY [DIRECTORY [...]]" >&2
echo "Usage: $(basename "$0") DIRECTORY [DIRECTORY [...]]" >&2
exit 1
fi
while [ "$1" != "" ] ; do
REP="$1"
while [ -n "$1" ] ; do
dir="$1"
shift
if [ ! -d "$REP" ] ; then
echo "Warning! \"$REP\" is not a directory: ignoring." >&2
if [ ! -d "$dir" ] ; then
echo "Warning! \"$dir\" is not a directory: ignoring." >&2
continue
fi
TARGET=$(basename "$REP")
REP=$dirname "$REP")
target="$(basename "$dir")"
dir="$(dirname "$dir")"
if [ "$TARGET" = "." -o "$TARGET" = ".." ] ; then
if [ "$target" = "." ] || [ "$target" = ".." ] ; then
echo "Target cannot end by « . » or « .. »!" >&2
exit 2
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
mv -n "$TARGET"/* .
if [ "$(echo "$target"/*)" != "$target/*" ] ; then
mv -n "$target"/* .
fi
if [ "$(echo "$TARGET"/.[!.]*)" != "$TARGET/.[!.]*" ] ; then
mv -n "$TARGET"/.[!.]* .
if [ "$(echo "$target"/.[!.]*)" != "$target/.[!.]*" ] ; then
mv -n "$target"/.[!.]* .
fi
rmdir "$TARGET"
rmdir "$target"
done
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4