You can use the following Bash command to dump all current environment variables into a .envrc file:
export -p | sed 's/^declare -x //' > .envrcexport -plists all exported environment variables.sed 's/^declare -x //'removes thedeclare -xprefix, leaving justVAR=VALUEpairs.> .envrcwrites the output to the.envrcfile.
If you're using direnv, ensure .envrc is loaded by running:
echo 'source_env .envrc' >> .envrc
direnv allowWould you like to filter out specific variables (e.g., PATH, PWD)?
https://gist.github.com/and1truong/65a122dac62eef6d8f697def2d6e2e96