Skip to content

Instantly share code, notes, and snippets.

@karmajunkie
Created August 6, 2010 19:00
Show Gist options
  • Save karmajunkie/511789 to your computer and use it in GitHub Desktop.
Save karmajunkie/511789 to your computer and use it in GitHub Desktop.
Host heroku.com
HostName heroku.com
User git
IdentityFile ~/.ssh/heroku.identity
IdentitiesOnly yes
# INTRODUCTION
# This script makes switching between multiple Heroku accounts easier by replacing existing Heroku
# account crendentials (i.e. ~/.heroku/crendentials) with new account credentials. This script assumes
# that your various Heroku account credential files are named as <account>.credentials and located in
# the default Heroku folder (as mentioned earlier).
# USAGE
# Format: ruby switch.rb <account>
# Example: ruby switch.rb default
# CONFIGURATION
HEROKU_HOME = File.join ENV["HOME"], ".heroku"
CREDENTIALS_FILE = "credentials"
DEFAULT_ACCOUNT = "keith"
# EXECUTION
account = ARGV.empty? ? DEFAULT_ACCOUNT : ARGV.first
account_path = File.join HEROKU_HOME, account + '.' + CREDENTIALS_FILE
credentials_path = File.join HEROKU_HOME, CREDENTIALS_FILE
ssh_path = File.join ENV['HOME'], ".ssh"
puts "\nSwitching to the \"#{account}\" Heroku account..."
if File.exists? account_path
system "cp -f #{account_path} #{credentials_path}"
else
puts "ERROR: Heroku account credentials do not exist!"
end
if File.exists?(File.join(ssh_path, "#{account}.identity"))
system "rm #{File.join(ssh_path, "heroku.identity")} && ln -s #{File.join(ssh_path, "#{account}.identity")} #{File.join(ssh_path, "heroku.identity")}"
system "rm #{File.join(ssh_path, "heroku.identity.pub")} && ln -s #{File.join(ssh_path, "#{account}.identity.pub")} #{File.join(ssh_path, "heroku.identity.pub")}"
else
system "rm #{File.join(ssh_path, "heroku.identity")} && ln -s #{File.join(ssh_path, "id_rsa")} #{File.join(ssh_path, "heroku.identity")}"
system "rm #{File.join(ssh_path, "heroku.identity.pub")} && ln -s #{File.join(ssh_path, "id_rsa.pub")} #{File.join(ssh_path, "heroku.identity.pub")}"
end
puts "Heroku account switch complete.\n\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment