#!/bin/bash
__SUMMARY__=$(cat <<"__TLDR__"
moveandreplace SOURCE DESTINATION

Move a directory and create a new directory where it was.
__TLDR__
)

Prog=${0##*/}

fail () {
    set +exu
    ret=${1}
    shift
    echo "$Prog:" "$@" >&2
    exit "$ret"
}

usage () {
    echo >&2 "$__SUMMARY__"
    exit "$1"
}

if [[ $* == -h || $* == --help ]]; then
    usage 0
fi

set -o nounset

if [[ $# != 2 ]]
then
    echo >&2 "Incorrect number of arguments"
    echo >&2
    usage 2
fi
From=$1
To=$2

mv -f "$From" "$To" || fail 3 "Failed to move"
mkdir "$From" || fail 4 "Failed to create"



# vim:et:sw=4:sts=4:ts=8
