Skip to content

Instantly share code, notes, and snippets.

@enthooz
Created September 7, 2011 18:34
Show Gist options
  • Save enthooz/1201334 to your computer and use it in GitHub Desktop.
Save enthooz/1201334 to your computer and use it in GitHub Desktop.
Automatically Change Heroku Accounts for Different Projects
heroku accounts:set ACCOUNT_NAME
__load_cdrc() # called from .rvm/scripts/cd
{
local working_dir
working_dir="${1:-"$PWD"}"
if [[ -f "$working_dir/.cdrc" ]]; then
echo "Loading .cdrc..."
source "$working_dir/.cdrc"
fi
}
__rvm_after_cd()
{
rvm_hook="after_cd"
source "${rvm_scripts_path:-"$rvm_path/scripts"}/hook"
#__rvm_unset_exports
if type -t __load_cdrc -eq 'function' > /dev/null; then
__load_cdrc
fi
}
@enthooz
Copy link
Author

enthooz commented Sep 7, 2011

Requires that you first install the Heroku Accounts plugin (https://github.com/ddollar/heroku-accounts) and add an account to the plugin (heroku accounts:add ACCOUNT_NAME). After setting this up, you can create a .cdrc file in any directory which will be run as a shell script upon entering that directory. One pitfall is that the .cdrc file also loaded after running cd .. which is often unnecessary.

  1. Modify .rvm/scripts/cd to call a __load_cdrc function if it has been defined. Find the __rvm_after_cd function and add the last three lines in the function as shown above.
  2. Define the __load_cdrc function in ~/.profile to load a .cdrc file in the current directory if it exists.
  3. Inside the directory for a Heroku app, create a .cdrc file including the following line.

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