open-remote 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/open-remote +9 -0
- data/lib/open-remote.rb +65 -0
- data/lib/or-browser.rb +98 -0
- data/lib/or-version.rb +6 -0
- data/man/git-open-remote.1 +91 -0
- data/readme.md +72 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a9c6d91ffe2013b860e16139487b2da212516de5
|
4
|
+
data.tar.gz: 9e2cf896cbbdb1862d199de389f02ef20154dcff
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c586857a67c1ce81215130c8c0a02208b2ca202da37b1607804b2b67437c4090e92951f7a4bf7f23b6a43f9c4a40f8785e228aa2a4e946eb5dcd92ae4ba86320
|
7
|
+
data.tar.gz: b51869d4aa9ce4d94dd6a36f33a57c892fe491cb30aa2f3024e7cd31bd06fd9abbee3428392fd821ad0b0be6aeef94e48f7e461a44ca65b8e34d8df34a9264f8
|
data/bin/open-remote
ADDED
data/lib/open-remote.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# open-remotes parsing and opening
|
2
|
+
|
3
|
+
require "colored"
|
4
|
+
require "or-version"
|
5
|
+
require "or-browser"
|
6
|
+
|
7
|
+
class OpenRemote
|
8
|
+
extend OpenRemote::Browser
|
9
|
+
|
10
|
+
def run(args)
|
11
|
+
arg = args.shift
|
12
|
+
case arg
|
13
|
+
when nil # open first remote
|
14
|
+
Browser.browse remote
|
15
|
+
|
16
|
+
when "--help", "-h"
|
17
|
+
puts OpenRemote::Help
|
18
|
+
|
19
|
+
when "--version", "-v"
|
20
|
+
puts OpenRemote::Version
|
21
|
+
|
22
|
+
when "--alias"
|
23
|
+
system "git config --global alias.open '!open-remote'"
|
24
|
+
|
25
|
+
when "--unalias"
|
26
|
+
system "git config --global --unset alias.open"
|
27
|
+
|
28
|
+
else # check against remotes
|
29
|
+
Browser.browse remote(arg)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def remote(search = /.*/)
|
34
|
+
remote = remotes.find { |remote| remote.match search }
|
35
|
+
|
36
|
+
raise "No remotes found that match #{search}. All remotes:\n".green +
|
37
|
+
remotes.join("\n") if remote.nil?
|
38
|
+
|
39
|
+
remote
|
40
|
+
end
|
41
|
+
|
42
|
+
def remotes
|
43
|
+
%x{git remote -v}.split("\n").map { |r| r.split[1] }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
# large constant strings
|
49
|
+
|
50
|
+
OpenRemote::Help = <<-HELP
|
51
|
+
open-remote - git remote opening tool.
|
52
|
+
|
53
|
+
`git open-remote` opens the first remote.
|
54
|
+
|
55
|
+
to open a specific remote, specify the host:
|
56
|
+
|
57
|
+
`git open-remote bit`,
|
58
|
+
`git open-remote bucket`,
|
59
|
+
`git open-remote bitbucket`,
|
60
|
+
will all open bitbucket remote in the browser.
|
61
|
+
|
62
|
+
Tested against github, bitbucket, and heroku repos.
|
63
|
+
|
64
|
+
HELP
|
65
|
+
|
data/lib/or-browser.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
# Detect operating system
|
2
|
+
#
|
3
|
+
module OpenRemote::OS
|
4
|
+
def os_name
|
5
|
+
if mac?
|
6
|
+
"mac"
|
7
|
+
elsif dos?
|
8
|
+
"dos"
|
9
|
+
elsif nix?
|
10
|
+
"nix"
|
11
|
+
else
|
12
|
+
raise "Unknown operating system."
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def mac?
|
17
|
+
(/darwin/ =~ RUBY_PLATFORM) != nil
|
18
|
+
end
|
19
|
+
|
20
|
+
def dos?
|
21
|
+
(/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def nix?
|
25
|
+
not (dos? || mac?)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
# Web browser opening commands
|
31
|
+
#
|
32
|
+
module OpenRemote::Browser end
|
33
|
+
class << OpenRemote::Browser
|
34
|
+
include OpenRemote::OS
|
35
|
+
|
36
|
+
# Generate and open approprate website from ssh/git link
|
37
|
+
#
|
38
|
+
def browse(remote)
|
39
|
+
open prepare remote
|
40
|
+
end
|
41
|
+
|
42
|
+
# Return the right command for opening a website from the terminal
|
43
|
+
#
|
44
|
+
def browser
|
45
|
+
case os_name
|
46
|
+
when "mac"
|
47
|
+
"open "
|
48
|
+
when "dos"
|
49
|
+
"start "
|
50
|
+
when "nix"
|
51
|
+
"xdg-open "
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# Make the system call to open up a website
|
56
|
+
#
|
57
|
+
def open(url)
|
58
|
+
puts "Opening: ".green + url
|
59
|
+
system browser + url
|
60
|
+
end
|
61
|
+
|
62
|
+
# Parse remote to determine whether it is https/ssh, give link
|
63
|
+
#
|
64
|
+
def prepare(url)
|
65
|
+
hb = "https://" # https base url
|
66
|
+
if /^https:\/\/git\.heroku/.match(url) # is heroku, change to app
|
67
|
+
https_to_app hb + "dashboard.heroku.com/apps/", url
|
68
|
+
|
69
|
+
elsif /^https/.match(url) # is website, return w/o .git ending
|
70
|
+
url.sub(/\.git$/, "")
|
71
|
+
|
72
|
+
elsif /^git/.match(url) # is ssh link, change to website
|
73
|
+
ssh_to_https hb, url
|
74
|
+
|
75
|
+
else # unknown, return a generic link
|
76
|
+
raise "Malformed remote url: " + url
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# url: git@host:user/repo.git
|
81
|
+
# out: https://host/user/repo
|
82
|
+
def ssh_to_https(base, url)
|
83
|
+
info = url.partition("@").last
|
84
|
+
host = info.partition(":").first
|
85
|
+
user_repo = info.partition(":").last
|
86
|
+
user_repo.sub!(/\.git$/, "")
|
87
|
+
"#{base}#{host}/#{user_repo}"
|
88
|
+
end
|
89
|
+
|
90
|
+
# url: https://git.heroku.com/app.git
|
91
|
+
# out: https://dashboard.heroku.com/apps/<app>
|
92
|
+
def https_to_app(base, url)
|
93
|
+
app = url.partition(".com/").last
|
94
|
+
app.sub!(/\.git$/, "")
|
95
|
+
base + app
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
data/lib/or-version.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
.\" generated with Ronn/v0.7.3
|
2
|
+
.\" http://github.com/rtomayko/ronn/tree/0.7.3
|
3
|
+
.
|
4
|
+
.TH "README20160107\-33310\-1YIAS53" "" "January 2016" "" ""
|
5
|
+
\fIhttps://badge\.fury\.io/rb/open\-remote\fR \fIhttps://travis\-ci\.org/jeremywrnr/open\-remote\fR \fIhttp://jeremywrnr\.com/mit\-license\fR
|
6
|
+
.
|
7
|
+
.P
|
8
|
+
open\-remote \- a simple git remote opening tool\. works for:
|
9
|
+
.
|
10
|
+
.IP "" 4
|
11
|
+
.
|
12
|
+
.nf
|
13
|
+
|
14
|
+
\- github
|
15
|
+
\- bitbucket
|
16
|
+
\- heroku
|
17
|
+
.
|
18
|
+
.fi
|
19
|
+
.
|
20
|
+
.IP "" 0
|
21
|
+
.
|
22
|
+
.P
|
23
|
+
if there are other git hosting websites that you would like to add, either let me know or make a pull request with the augmentation for that host\.
|
24
|
+
.
|
25
|
+
.SH "setup"
|
26
|
+
.
|
27
|
+
.nf
|
28
|
+
|
29
|
+
[sudo] gem install open\-remote
|
30
|
+
.
|
31
|
+
.fi
|
32
|
+
.
|
33
|
+
.SH "usage"
|
34
|
+
.
|
35
|
+
.nf
|
36
|
+
|
37
|
+
git open\-remote
|
38
|
+
.
|
39
|
+
.fi
|
40
|
+
.
|
41
|
+
.P
|
42
|
+
opens the first git remote\. to open a specific remote, specify some part (or all) of the host name\. for example:
|
43
|
+
.
|
44
|
+
.IP "" 4
|
45
|
+
.
|
46
|
+
.nf
|
47
|
+
|
48
|
+
git open\-remote bit
|
49
|
+
git open\-remote bucket
|
50
|
+
git open\-remote bitbucket
|
51
|
+
.
|
52
|
+
.fi
|
53
|
+
.
|
54
|
+
.IP "" 0
|
55
|
+
.
|
56
|
+
.P
|
57
|
+
will all open the current repository\'s bitbucket remote in the browser\.
|
58
|
+
.
|
59
|
+
.SH "about"
|
60
|
+
the original idea for this came from my friend charlie \fI\fR who initially provided me with a simple git alias that would do the same, but it only worked for repos that were https and was not platform independent\. I was also inspired by the git\-up \fI\fR ruby gem in how seamlessly it integrated with git\. Here is the original git alias (made to work on osx), which charlie wrote (plop it in your \.gitconfig, if you don\'t want to install a ruby gem to open your git remotes):
|
61
|
+
.
|
62
|
+
.IP "" 4
|
63
|
+
.
|
64
|
+
.nf
|
65
|
+
|
66
|
+
[alias]
|
67
|
+
open\-remote = "!open $(git remote \-v $@ | grep \-o \'http\e\eS*\' | head \-1); :"
|
68
|
+
.
|
69
|
+
.fi
|
70
|
+
.
|
71
|
+
.IP "" 0
|
72
|
+
.
|
73
|
+
.SH "testing"
|
74
|
+
.
|
75
|
+
.nf
|
76
|
+
|
77
|
+
bundle || gem install bundler
|
78
|
+
rake
|
79
|
+
.
|
80
|
+
.fi
|
81
|
+
.
|
82
|
+
.SH "todos"
|
83
|
+
.
|
84
|
+
.IP "\(bu" 4
|
85
|
+
adding ronn docgen, with rake
|
86
|
+
.
|
87
|
+
.IP "\(bu" 4
|
88
|
+
activitaing travisci tracking
|
89
|
+
.
|
90
|
+
.IP "" 0
|
91
|
+
|
data/readme.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
open-remote
|
2
|
+
===========
|
3
|
+
|
4
|
+
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/open-remote.svg)](https://badge.fury.io/rb/open-remote)
|
6
|
+
[![Build Status](https://travis-ci.org/jeremywrnr/open-remote.svg?branch=master)](https://travis-ci.org/jeremywrnr/open-remote)
|
7
|
+
[![MIT](https://img.shields.io/npm/l/alt.svg?style=flat)](http://jeremywrnr.com/mit-license)
|
8
|
+
|
9
|
+
|
10
|
+
open-remote - a simple git remote opening tool.
|
11
|
+
|
12
|
+
tested and works well for:
|
13
|
+
|
14
|
+
- github
|
15
|
+
- bitbucket
|
16
|
+
- heroku
|
17
|
+
|
18
|
+
if there are other git hosting websites that you would like to use this with,
|
19
|
+
either let me know or make a pull request with the augmentation for that host.
|
20
|
+
|
21
|
+
|
22
|
+
## setup
|
23
|
+
|
24
|
+
[sudo] gem install open-remote
|
25
|
+
|
26
|
+
making a git alias for 'git open' in your `.gitconfig`:
|
27
|
+
|
28
|
+
open-remote --alias
|
29
|
+
|
30
|
+
removing the alias, if you don't want it anymore:
|
31
|
+
|
32
|
+
open-remote --unalias
|
33
|
+
|
34
|
+
|
35
|
+
## usage
|
36
|
+
|
37
|
+
git open
|
38
|
+
|
39
|
+
opens the first git remote. to open a specific remote, specify some part (or
|
40
|
+
all) of the host name. for example:
|
41
|
+
|
42
|
+
git open bit
|
43
|
+
git open bucket
|
44
|
+
git open bitbucket
|
45
|
+
|
46
|
+
will all open the current repository's bitbucket remote in the browser.
|
47
|
+
|
48
|
+
|
49
|
+
## about
|
50
|
+
|
51
|
+
the original idea for this came from my friend [charlie][cel] who initially
|
52
|
+
provided me with a simple git alias that would do the same, but it only worked
|
53
|
+
for repos that were https and was not platform independent. I was also inspired
|
54
|
+
by the [git-up][gup] ruby gem in how seamlessly it integrated with git. Here is
|
55
|
+
the original git alias (made to work on osx), which charlie wrote (plop it in
|
56
|
+
your .gitconfig, if you don't want to install a ruby gem to open your git
|
57
|
+
remotes):
|
58
|
+
|
59
|
+
```
|
60
|
+
[alias]
|
61
|
+
open-remote = "!open $(git remote -v $@ | grep -o 'http\\S*' | head -1); :"
|
62
|
+
```
|
63
|
+
|
64
|
+
[cel]:https://github.com/clehner
|
65
|
+
[gup]:https://github.com/aanand/git-up
|
66
|
+
|
67
|
+
|
68
|
+
## testing
|
69
|
+
|
70
|
+
bundle || gem install bundler
|
71
|
+
rake
|
72
|
+
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: open-remote
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeremy Warner
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: colored
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ronn
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: open a git repo's web remote from your terminal.
|
70
|
+
email: jeremywrnr@gmail.com
|
71
|
+
executables:
|
72
|
+
- open-remote
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- bin/open-remote
|
77
|
+
- lib/open-remote.rb
|
78
|
+
- lib/or-browser.rb
|
79
|
+
- lib/or-version.rb
|
80
|
+
- man/git-open-remote.1
|
81
|
+
- readme.md
|
82
|
+
homepage: http://github.com/jeremywrnr/open-remote
|
83
|
+
licenses:
|
84
|
+
- MIT
|
85
|
+
metadata: {}
|
86
|
+
post_install_message: Run 'open-remote --alias' to add 'git open'
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 2.5.1
|
103
|
+
signing_key:
|
104
|
+
specification_version: 4
|
105
|
+
summary: open a git repo's remote from your terminal.
|
106
|
+
test_files: []
|