Last active
October 29, 2015 11:51
-
-
Save diskshima/95d79726f66a8ef990d2 to your computer and use it in GitHub Desktop.
Script to open Git Repository's Remote URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
# Please run the below command first. | |
# gem install git uri-ssh_git launchy | |
require 'git' | |
require 'uri/ssh_git' | |
require 'launchy' | |
dir = '.' | |
remote_name = 'origin' | |
nobrowser = false | |
OptionParser.new do |opts| | |
opts.banner = "Usage: #{__FILE__} [options]" | |
opts.on('-d DIRECTORY', '--directory DIRECTORY', 'Directory. Defaults to current directory') do |d| | |
dir = d | |
end | |
opts.on('-n', '--no-browser', 'Do not open URL in browser.') do |n| | |
nobrowser = true | |
end | |
opts.on('-r REMOTE_NAME', '--remote REMOTE_NAME', 'Remote name. Defaults to origin') do |r| | |
remote_name = r | |
end | |
end.parse! | |
git = Git.open(dir) | |
remotes = git.remotes | |
remote = remotes.select { |r| r.name == remote_name }.first | |
remote_url = remote.url | |
url = URI::SshGit.parse(remote_url) | |
http_url = "https://#{url.host}#{url.path}" | |
puts http_url | |
Launchy.open(http_url) unless nobrowser |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment