You can add the following functions for your shell, loadenv
will search for .env file if found will export all to the shell session with unloadenv
will unset the variables so you can start again, reloadenv
will reread the .env file.
function loadenv {
test -f .env || echo "No .env file in the working directory"
oldenv=$(env|sort)
export $(grep -v '^#' .env | xargs -d '\n')
diff <(echo "$oldenv") <(env | sort)
}
function unloadenv {
test -f .env || echo "No .env file in the working directory"
oldenv=$(env|sort)
unset $(grep -v '^#' .env | sed -E 's/(.*)=.*/\1/' | xargs -d '\n')
diff <(echo "$oldenv") <(env | sort)
}
function reloadenv {
unloadenv
loadenv
}