Skip to content

Instantly share code, notes, and snippets.

@agush22
Created August 18, 2012 05:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agush22/3384721 to your computer and use it in GitHub Desktop.
Save agush22/3384721 to your computer and use it in GitHub Desktop.
Simple SSH key switcher for multiple Heroku accounts
#!/usr/bin/env ruby
require 'fileutils'
class Switcher
include FileUtils
home = File.expand_path('~/')+"/"
@@dir = home+".ssh/"
@@current = home + ".switcher"
def switch_accounts(account)
#missing all types of checks
#check for current account
#check if account keys exist
#check everything
file = File.open(@@current).first
if account == file
puts "Same account"
else
cp(@@dir+account+"/id_rsa", @@dir+"id_rsa", :verbose => true)
cp(@@dir+account+"/id_rsa.pub", @@dir+"id_rsa.pub", :verbose => true)
File.open(@@current, 'w') {|f| f.write(account) }
puts "Changed account to " + account
end
end
def get_current
puts File.open(@@current).first
end
end
sw = Switcher.new
if ARGV.first.nil?
puts "Missing arguments"
elsif ARGV.first == "current"
sw.get_current
else
sw.switch_accounts(ARGV.first)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment