Skip to content

Instantly share code, notes, and snippets.

@vanntastic
Created July 27, 2010 19:29
Show Gist options
  • Save vanntastic/492727 to your computer and use it in GitHub Desktop.
Save vanntastic/492727 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby -wKU
if ARGV[0].nil?
puts " gh_search [name_of_repo]: \n - Copies repo url to clipboard (via pbcopy) if only one repo is found"
else
search_string = "Searching github for #{ARGV[0]}...."
border = "="*search_string.length
puts "#{search_string}\n#{border}"
res = `gh search #{ARGV[0]}`.split("\n")
if res.length == 1
user, repo = res.first.split("/").first, res.first.split("/").last
repo_url = "http://github.com/#{user}/#{repo}.git"
system("echo #{repo_url} | pbcopy")
puts "#{repo_url} has been copied to the clipboard!"
else
puts "#{res.length} Repositories found!"
res.each do |r|
puts "- #{r} (gh_search #{r.split('/').last} to copy)"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment