Automatically Loading the .env File in Your VS Code Embed Terminal
Simple, this example is based on a Mac with Apple chip.
But you can easily adapt for your environment.
How to Do It
1 — Open the file ~/.zprofile (create it if it doesn’t exist);
2 — Add the following code:
# Loading `.env` on VS Code embeded terminal
if [[ "$TERM_PROGRAM" == "vscode" && -f ".env" ]]; then
source .env && \
echo "✅ loaded .env"
fi
3 — Save the file;
4 — Close and reopen your embedded terminal in VS Code;
5 — Voilà! Your environment variables are now available in your terminal session;
By following these steps, you can automate the process of loading your .env file in the VS Code terminal, making it more convenient to work with your environment variables.