#! /bin/bash
#
# tmp.bash
# Copyright (C) 2018 salt <salt@lap-th-e560-0>
#
# Distributed under terms of the MIT license.
#

# Define variables
name="$(basename "$0" .sh)"
tmpdir="$(mktemp -d)"
# Verify them
[ -z ${tmpdir+x} ] && exit 2
# Define functions
function log() {
	[ -z ${1+x} ] && return 1
	# shellcheck disable=1117
	printf "%b: %s\n" \
		"$name" \
		"$1"
}
function cleanup() {
	rm -rf "${tmpdir}"
}
trap "cleanup" EXIT
# Do the do
log "This folder will be removed when this shell exits"
(
cd "${tmpdir}" || exit 50
exec "$SHELL"
)
cleanup