Class: OpenRemote
- Inherits:
-
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 =
"1.0.0"
- HELP =
"A tool for git remote opening tool. Open the remote url:\n \n git open\n \nOptions:\n \n -h, --help show help\n -v, --version show open-remote version\n -o, --output show output without opening\n --alias add open-remote to git alias\n --unalias remove open-remote from git\n \nTo open a particular remote, specify the host:\n \n git open bit\n git open bucket\n git open bitbucket\n \nThese all open bitbucket's remote url in the browser.\nTested against github, bitbucket, and gitea repos.\n"
Instance Method Summary
collapse
Methods included from Browser
browse, browser, git_at_to_https, git_colon_to_https, open_url, prepare, ssh_to_https
Methods included from OS
#os_name
Instance Method Details
#no_repo? ⇒ 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
|
#remotes ⇒ Object
59
60
61
62
63
64
65
66
|
# File 'lib/open-remote.rb', line 59
def remotes
`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
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
Browser.browse remote(arg)
end
end
|