giturl 1.0.5 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/bin/giturl +18 -17
- data/lib/giturl/version.rb +1 -1
- data/lib/giturl.rb +30 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82614879807fdeb3eabbc86b9584d60d52bbd3173a4813375430b5492b0fbe64
|
4
|
+
data.tar.gz: ae6e151e129cfb414e7bbe5416133ceaa8b236d9ba9856b67e402a5ee86bca7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec045d7c18ea3b26f17dc56b449f4f35a731aff9376226820ddb6948e056f18de32903370d4cdc23c519cfb008e717d6343298497c1c945224fcf3cb846d8ca1
|
7
|
+
data.tar.gz: 110543865646d88983386ddd473ed6acce2933545851bcd7df4fce9503761141e7240878506db5c3e77d779db9f446b2394c0b1ba658dd4a08f59d900f6b59bd
|
data/.gitignore
CHANGED
data/bin/giturl
CHANGED
@@ -6,24 +6,25 @@
|
|
6
6
|
# giturl.rb [-o or --open] dir1 [dir2, dir3, ...]
|
7
7
|
# output
|
8
8
|
# <url of dir1> [<url of dir2>, <url of dir3>, ...]
|
9
|
-
# and if -o is given, open urls
|
9
|
+
# and if -o is given, open urls in your browser.
|
10
10
|
#
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
opt.
|
12
|
+
if $PROGRAM_NAME == __FILE__
|
13
|
+
require 'optparse'
|
14
|
+
require 'giturl'
|
15
|
+
opt = OptionParser.new
|
16
|
+
opt.on('-o', '--open', 'Open the URL directly in your browser.') { |v| v }
|
17
|
+
opt.on('-v', '--verbose', 'Turn on verbose mode.') { |v| v }
|
18
|
+
params = {}
|
19
|
+
opt.parse!(ARGV, into: params)
|
17
20
|
|
18
|
-
ARGV.each do |arg|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
print "#{url}\n"
|
28
|
-
system("open #{url}") if params[:open]
|
21
|
+
ARGV.each do |arg|
|
22
|
+
if Giturl::Giturl.git_managed?(arg)
|
23
|
+
url = Giturl::Giturl.url(arg)
|
24
|
+
print "#{url}\n"
|
25
|
+
system("open #{url}") if params[:open]
|
26
|
+
elsif params[:verbose]
|
27
|
+
print "Not git-managed-dir: #{arg}\n"
|
28
|
+
end
|
29
|
+
end
|
29
30
|
end
|
data/lib/giturl/version.rb
CHANGED
data/lib/giturl.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Giturl
|
5
|
+
class Giturl
|
6
|
+
def self.git_managed?(path)
|
7
|
+
stderr_old = $stderr.dup
|
8
|
+
$stderr.reopen('/dev/null')
|
9
|
+
inside = `git -C #{path} rev-parse --is-inside-work-tree`.chomp
|
10
|
+
$stderr.flush
|
11
|
+
$stderr.reopen stderr_old
|
12
|
+
inside == 'true'
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.url(path)
|
16
|
+
gitdir_prefix = `git -C #{path} rev-parse --show-prefix`.chomp
|
17
|
+
gitdir_branch = `git -C #{path} rev-parse --abbrev-ref HEAD`.chomp
|
18
|
+
remote_origin_url = `git -C #{path} config --get remote.origin.url`.chomp
|
19
|
+
|
20
|
+
# remote_origin_url: git@github.com:shinyaohtani/giturl.git
|
21
|
+
baseurl = remote_origin_url.gsub(/:/, '/').gsub(/^.*@/, 'https://').gsub(/\.git$/, '')
|
22
|
+
|
23
|
+
"#{baseurl}/tree/#{gitdir_branch}/#{gitdir_prefix}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.safe_url(path)
|
27
|
+
url(path) if git_managed?(path)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: giturl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- shinyaohtani
|
@@ -55,6 +55,7 @@ files:
|
|
55
55
|
- bin/giturl
|
56
56
|
- bin/setup
|
57
57
|
- giturl.gemspec
|
58
|
+
- lib/giturl.rb
|
58
59
|
- lib/giturl/version.rb
|
59
60
|
homepage: https://github.com/shinyaohtani/giturl
|
60
61
|
licenses: []
|