from subprocess import run
from shutil import which
-from os import environ, mkdir
+from os import environ, mkdir, scandir
from pathlib import PurePath
__programs__: dict = { }
env["HOME"] = home.as_posix()
cmd = startsh.as_posix()
- return run(cmd, cwd=dir, env=env).returncode
+ rc = run(cmd, cwd=dir, env=env).returncode
+
+ # Remove newly-created _HOME_ if it is still empty
+ if not any(scandir(home.as_posix())):
+ home.rmdir()
+
+ return rc
+
+ print("Directory is empty.")
+