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