Skip to content

Instantly share code, notes, and snippets.

@and1truong
Created January 30, 2025 04:19
Show Gist options
  • Save and1truong/27ac324d55df1c11a66007799e4c67b9 to your computer and use it in GitHub Desktop.
Save and1truong/27ac324d55df1c11a66007799e4c67b9 to your computer and use it in GitHub Desktop.

You can use the following Bash command to dump all current environment variables into a .envrc file:

export -p | sed 's/^declare -x //' > .envrc

Explanation:

  • export -p lists all exported environment variables.
  • sed 's/^declare -x //' removes the declare -x prefix, leaving just VAR=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)?

@and1truong
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment