Skip to content

Instantly share code, notes, and snippets.

@synotna
Last active August 29, 2015 14:22
Show Gist options
  • Save synotna/b06d38a7fdbbbbcd3ba6 to your computer and use it in GitHub Desktop.
Save synotna/b06d38a7fdbbbbcd3ba6 to your computer and use it in GitHub Desktop.
How to use environment variable files with IDEA with remote interpreter

Want to use environment variables for your IDEA project?

  • Want you use .env files like you do for all other tools?
  • Don't want to include hacks in your project code for loading environment variables just for development?
  • Don't want to use the nightmare environment variables features of IDEA?
  • Want to easily be able to switch environments without losing your sanity?

Here's how!

  • Create a user, recommend per project and store project files in under user's homedir rather than your own
    • otherwise you need to add it & the original user to each others groups, and keep file permissions in mind
  • In the .bashrc for the user: export $(cat /path/to/env/file | xargs)

Pro-tip: make this path a soft link to the current environment you want to use, and use a bash script for switching where the link points to - this could even be used in run configurations for switching in your IDE!

#!/bin/bash
PROJECT_ROOT=/path/to/project
if [ -z $1 ] ; then
echo "No environment specified"
elif [ -a "env/$1.env" ] ; then
rm -f $PROJECT_ROOT/.env
cd $PROJECT_ROOT
ln -s ../env/$1.env .env
else
echo "Environemnt $1.env does not exist"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment