-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgto
executable file
·36 lines (32 loc) · 987 Bytes
/
gto
1
2
3
4
5
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
34
35
36
#!/usr/bin/env ruby
require 'rubygems' unless RUBY_VERSION.to_i > 1.9
require 'git'
call_path = ENV["PWD"]
remote_name = ARGV[0]
begin
git = Git.open(call_path)
rescue ArgumentError => e
system("echo \"gto: #{call_path}: Not a git repository\"")
exit
else
if git.remotes.length > 1
if !remote_name
system("echo 'gto: Please enter a remote name'")
exit
end
else
remote_name = git.remotes.first.name unless remote_name
end
if git && git.remote(remote_name).url
remote_url = git.remote(remote_name).url.gsub(/git@/, 'http://').gsub(/\.git/, '').gsub(/\.com:/, '.com/')
sys = `uname -s`.chomp
if sys == "Darwin"
open_cmd = "open"
elsif sys == "Linux"
open_cmd = "xdg-open"
end
`#{open_cmd} \"#{remote_url}\"`
else
system("echo \"gto: #{remote_name}: No such remote. Available remotes: #{git.remotes.join(", ")}\"")
end
end