Skip to content

Instantly share code, notes, and snippets.

@kastner
Created November 1, 2008 16:36
Show Gist options
  • Select an option

  • Save kastner/21543 to your computer and use it in GitHub Desktop.

Select an option

Save kastner/21543 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
hosts = []
hosts << open("#{ENV["HOME"]}/.ssh/config").read.scan(/host\s(.+?)\n/i).uniq
hosts << open("#{ENV["HOME"]}/.ssh/known_hosts").read.scan(/^(.*) ssh/).map do |h|
host = h[0].gsub(/,.*/,'')
host = "'#{$1} -p #{$2}'" if host.match(/\[(.*)\]:(.*)/)
host
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment