Inspired by direnv
https://github.com/direnv/direnv
posh-direnv is an environment switcher for the PowerShell. It executes ".psdirenv" in the current directory. You can easily set unique environment variables for each directory.
You can install from PowerShell Gallery. posh-direnv
$ Install-Module -Name posh-direnv
$ mkdir work
$ cd work
$ Edit-DirEnvRc
Since notepad starts up, edit .psdirenv. When you exit the editor .psdirenv is authorised and applied if the file was modified.
$ cat .\.psenvrc
Write-Host "Hello posh-direnv"
$Host.UI.RawUI.WindowTitle="posh-direnv"
Activate the new powershell and check its operation. If you move to a directory with .psdirenv, it will be displayed as below and the console title will be changed.
$ cd work
psenvdir: loading work/.psenvrc
Hello posh-direnv
psenvdir: export
Once you exit the directory tree and move again the environment changes will be reversed and reapplied if you reenter the directory.
If you edit the .psenvrc file yourself or move it between directories you must authorise it before it will be applied.
$ cd work
psenvdir: work/.psenvrc not in allow list
$ Approve-DirEnvRc
psenvdir: loading work/.psenvrc
Hello posh-direnv
psenvdir: export
You can unauthorise a .psenvrc file by calling Deny-DirEnvRc and cleanup the authorised list in the event directories are deleted before being denied by calling Repair-DirEnvAuth.