Skip to content

Instantly share code, notes, and snippets.

@paustin01
Created December 19, 2013 17:21
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 paustin01/8042926 to your computer and use it in GitHub Desktop.
Save paustin01/8042926 to your computer and use it in GitHub Desktop.
Simple ruby script to launch Github in chrome from a mac (which could be parameterized) to a particular page for the repository that you're currently on in your shell. Feel free to tweak and improve to your heat's content.
#!/usr/bin/env ruby
remote = ARGV[0]
branch = ARGV[1] || '.'
page = ARGV[2] || 'tree'
# Ensure we're in a git repo
unless Dir.glob('.*').include?('.git')
puts "Must be in a git repo"
exit 1
end
# Validate remote
unless remote
puts "\nusage:\n"
puts " gitgo [remote] {branch|page} {page}"
exit 0
end
unless `git remote -v | grep fetch`.include?(remote)
puts "Invalid remote. Options are:"
puts `git remote -v`
exit 1
end
# Get the branch
if ['tree', 'commits', 'releases', 'pulls'].include?(branch)
# Prompt to confirm if page is actually a branch
#puts "Is '#{branch}' a page? [y,n]"
#is_page = STDIN.gets.chomp()
#if is_page == 'y'
page = branch
branch = `git branch | awk '/\\*/ { print $2; }'`.delete("\n")
#end
elsif branch == '.'
branch = `git branch | awk '/\\*/ { print $2; }'`.delete("\n")
end
# Don't set a branch if hitting certain pages
if ['pulls', 'releases'].include?(page)
branch = nil
end
# Get the uri of the remote passed
remote_uri = `git remote -v | grep fetch | awk '/#{remote}/ { print $2; }'`.delete("\n")
# Massage it if it's ssh
if remote_uri.include?('git@github')
remote_uri.gsub!("git@github.com:","https://github.com/")
end
# Built the full url
full_url = remote_uri.gsub(".git","/#{page}/#{branch}")
# Launch Chrome
system("open /Applications/Google\\ Chrome.app #{full_url}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment