Class: OpenRemote

Inherits:
Object
  • Object
show all
Extended by:
Browser
Defined in:
lib/or-version.rb,
lib/open-remote.rb

Overview

universal version tracking

Defined Under Namespace

Modules: Browser, OS

Constant Summary collapse

Version =
"0.5.1"
Help =

large constant strings

<<-HELP
A tool for git remote opening tool. Open the remote url:

    git open

Options:

    -h, --help    show help
    -v, --version show open-remote version
    -o, --output  show output without opening
    --alias       add open-remote to git alias
    --unalias     remove open-remote from git

To open a particular remote, specify the host:

    git open bit
    git open bucket
    git open bitbucket

These all open bitbucket's remote url in the browser.
Tested against github, bitbucket, and heroku repos.
HELP

Instance Method Summary collapse

Methods included from Browser

browse, browser, git_at_to_https, git_colon_to_https, https_to_app, open, prepare, ssh_to_https

Methods included from OS

#os_name

Instance Method Details

#no_repo?Boolean

Returns:

  • (Boolean)


37
38
39
40
# File 'lib/open-remote.rb', line 37

def no_repo?
  `git status 2>&1`.split("\n").first ==
    "fatal: Not a git repository (or any of the parent directories): .git"
end

#remote(search = /.*/) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/open-remote.rb', line 42

def remote(search = /.*/)
  if no_repo?
    puts "Not currently in a git repository.".red
    exit 1
  end

  remote_site = remotes.find { |r| r.each_value.any? { |d| d.downcase.match search } }

  if remote_site.nil?
    puts "No remotes found that match #{search.to_s.red}. All remotes:\n" +
      remotes.join("\n")
    exit 1
  else
    remote_site[:url]
  end
end

#remotesObject



59
60
61
62
63
64
# File 'lib/open-remote.rb', line 59

def remotes
  %x{git remote -v}.split("\n").map {|r| {
    :remote => r.split[0],
    :url => r.split[1],
  }}.uniq
end

#run(args) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/open-remote.rb', line 10

def run(args)
  arg = args.shift

  case arg
  when nil # open first remote
    Browser.browse remote

  when "--help", "-h"
    puts OpenRemote::Help

  when "--version", "-v"
    puts OpenRemote::Version

  when "--alias"
    system "git config --global alias.open '!open-remote'"

  when "--unalias"
    system "git config --global --unset alias.open"

  when "--output", "-o"
    puts Browser.prepare remote

  else # check against remotes
    Browser.browse remote(arg)
  end
end