Skip to content

Instantly share code, notes, and snippets.

@ericblue
Created May 13, 2020 19:52
Show Gist options
  • Save ericblue/9236b5b2742fd1b429b0b070d8b380c2 to your computer and use it in GitHub Desktop.
Save ericblue/9236b5b2742fd1b429b0b070d8b380c2 to your computer and use it in GitHub Desktop.
Sync .envrc and .env files for use in CLI and IntelliJ
#!/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