class Open
Public Instance Methods
cmd()
click to toggle source
Returns a command appropriate for executing at the command line.
# File lib/git-utils/open.rb, line 38 def cmd if options[:print] puts page_url "" else "#{open} #{page_url}" end end
page_url()
click to toggle source
Returns the URL for the repository page.
# File lib/git-utils/open.rb, line 18 def page_url if service == 'stash' && protocol == 'ssh' pattern = /(.*)@([^:]*):?([^\/]*)\/([^\/]*)\/(.*)\.git/ replacement = 'https://\2/projects/\4/repos/\5/browse?at=' + current_branch elsif service == 'stash' && protocol == 'http' pattern = /(.*)@([^:\/]*)(:?[^\/]*)\/(.*)scm\/([^\/]*)\/(.*)\.git/ replacement = 'https://\2\3/\4projects/\5/repos/\6/browse?at=' + current_branch elsif protocol == 'ssh' pattern = /(.*)@(.*):(.*)\.git/ replacement = 'https://\2/\3' elsif protocol == 'http' pattern = /https?\:\/\/(([^@]*)@)?(.*)\.git/ replacement = 'https://\3' end origin_url.sub(pattern, replacement) end
parser()
click to toggle source
# File lib/git-utils/open.rb, line 5 def parser OptionParser.new do |opts| opts.banner = "Usage: git open" opts.on("-p", "--print", "print URL instead of opening") do |opt| self.options.print = opt end opts.on_tail("-h", "--help", "this usage guide") do puts opts.to_s; exit 0 end end end
Private Instance Methods
linux?()
click to toggle source
Returns true if platform is Linux.
# File lib/git-utils/open.rb, line 66 def linux? RUBY_PLATFORM.match(/linux/) end
open()
click to toggle source
Returns the system-dependent ‘open` command.
# File lib/git-utils/open.rb, line 50 def open if os_x? 'open' elsif linux? 'xdg-open' else raise "Platform #{RUBY_PLATFORM} not supported" end end
os_x?()
click to toggle source
Returns true if platform is OS X.
# File lib/git-utils/open.rb, line 61 def os_x? RUBY_PLATFORM.match(/darwin/) end