Skip to content

Instantly share code, notes, and snippets.

@matthewtodd
Created November 11, 2009 07:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewtodd/231767 to your computer and use it in GitHub Desktop.
Save matthewtodd/231767 to your computer and use it in GitHub Desktop.
Handy Heroku credentials switcher.
#!/usr/bin/env ruby -wKU
# I use 2 different Heroku accounts, one for my own apps and one for Amani's.
# This script givens me a reasonable way to switch between them, with a little
# less typing than moving a symlink around. And I get to use abbrev!
require 'abbrev'
require 'pathname'
require 'yaml'
credentials = Pathname.new(ENV['HOME']).join('.heroku', 'credentials')
config = YAML.load(DATA)
current_user = credentials.readlines.first.chomp
available_users = config.keys - [current_user]
selected_user = available_users.abbrev[ARGV.shift]
if password = config[selected_user]
puts "Re-authenticating as #{selected_user}."
credentials.open('w') do |file|
file.puts(selected_user)
file.puts(password)
end
else
puts "You are #{current_user}."
end
__END__
matthew.todd@gmail.com: ELIDED
developer@amanikids.org: ELIDED
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment