Created
May 13, 2020 19:52
-
-
Save ericblue/9236b5b2742fd1b429b0b070d8b380c2 to your computer and use it in GitHub Desktop.
Sync .envrc and .env files for use in CLI and IntelliJ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Supports using environment variables from direnv in both CLI and IntelliJ | |
# CLI uses direnv .envrc (https://direnv.net/) | |
# IntelliJ uses .env files using the following plugin https://plugins.jetbrains.com/plugin/7861-envfile | |
# | |
# The master env config file is the .env file. Any edits using this script will export to an updated .envrc file | |
# Edit source .env file | |
pico .env | |
# Remove old .envrc file | |
unlink .envrc | |
# Copy .env to .envrc | |
ENVFILE=".env" | |
while IFS= read -r line | |
do | |
# Skip blank lines or comments | |
[[ "$line" =~ ^$|^#.*$ ]] && continue | |
echo "export $line" >> .envrc | |
done < "$ENVFILE" | |
# Apply new .envrc | |
direnv allow |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment