6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/git/open.rb', line 6
def self.execute
require "slop"
options = Slop.parse do |option|
option.on "-h".freeze, "--help".freeze, "Show this help".freeze
option.on "-v".freeze, "--version".freeze, "print the version".freeze do
puts_and_exit "git-open version #{Git::Open::VERSION}"
end
end
show_help(options) if options[:h] || options[:help] || ARGV.include?("help".freeze)
abort("Not a git repo".freeze) if `git rev-parse --is-inside-work-tree`.chomp! != "true".freeze
remotes = `git remote`.split("\n".freeze)
abort("No remote found".freeze) if remotes.empty?
url = if remotes.find { |remote| remote == "origin".freeze }
`git config --get remote.origin.url`.chomp!
else
`git config --get remote.#{remotes.first}.url`.chomp!
end
require "git/remote/parser"; require "launchy"
Launchy.open(open_url = Git::Remote::Parser.new.parse(url).html_url) do |exception|
puts "Attempted to open `#{open_url.to_s}' and failed because #{exception}"
end
end
|