dpu 0.1.0 → 0.3.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.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +45 -0
  3. data/Rakefile +8 -1
  4. data/lib/dpu/version.rb +1 -1
  5. data/lib/dpu.rb +15 -5
  6. metadata +20 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a136a963872583eb77ab03abe04b4f06a281e33f6bf3e74703eb1920545c2839
4
- data.tar.gz: 112faf5ef0d4ab660844a3c81eacf5cda68072ad00015fe0862ed7d242b26371
3
+ metadata.gz: e74102f4656827d87278839810c8567da7d5442b574c7d1bf37cf4efacfe678b
4
+ data.tar.gz: 87de6aa0a6534f2fae3426dcc71d8802387f71e46c8aae86e4edaac140b7d89f
5
5
  SHA512:
6
- metadata.gz: 95b54d43d7a9352b305047415af4f0eb9c379162ab52acbf89007b72e48df6253e21faf622e454584944b0fd8d4e4674b57af013f568389c92dcadefe9303259
7
- data.tar.gz: 58c2fe2c850536c1c3dcafbcac54e7a56c40a9b268570937ae25b4360e6ef172bac9d24e6e524a1d4b799fcb3e0b8c05073136df8f19e76c130b30b571bdc4eb
6
+ metadata.gz: 8fcb41b6badad655bef585317d7a4f27ab344a72fe574169a14dfd70547ac6ef79df92692f1ef86afb27d46e1c4c9fb0e59a5751abfe47d62a65ff84ccc55941
7
+ data.tar.gz: 56553802f7c6cad522369be264632e45fec627389d5eb0232c8cc6f63e83c8a0171d78d5677f7f1df7470bbe43aca1480b1b276a388068d027b782b12b5ed582
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # dpu: determine permanent URI
2
2
 
3
+ [![License X11](https://img.shields.io/badge/license-X11-blue.svg)](https://raw.githubusercontent.com/nishidayuya/dpu/master/LICENSE.txt)
4
+ [![Gem Version](https://badge.fury.io/rb/dpu.svg)](https://rubygems.org/gems/dpu)
5
+ [![Build Status](https://github.com/nishidayuya/dpu/workflows/ubuntu/badge.svg)](https://github.com/nishidayuya/dpu/actions?query=workflow%3Aubuntu)
6
+
3
7
  `dpu` command shows us permanent source-code URI.
4
8
 
5
9
  ```console
@@ -31,6 +35,47 @@ Get permanent source code URI with line range:
31
35
  $ dpu path_to_code start_line_number end_line_number
32
36
  ```
33
37
 
38
+ ### Emacs integration
39
+
40
+ Write following code to your `.emacs`, and evaluate it.
41
+
42
+ ```emacs-lisp
43
+ (define-key global-map (kbd "C-x L")
44
+ (lambda ()
45
+ (interactive)
46
+ (message
47
+ (concat
48
+ "Copied: "
49
+ (kill-new
50
+ (s-chomp
51
+ (shell-command-to-string
52
+ (concat
53
+ "dpu "
54
+ buffer-file-name
55
+ " "
56
+ (number-to-string (line-number-at-pos (region-beginning)))
57
+ (if mark-active (concat " " (number-to-string (line-number-at-pos (region-end)))))
58
+ )
59
+ )))))))
60
+ ```
61
+
62
+ Then type `C-x L` to copy permanent URI. `C-y` to paste it.
63
+
64
+ ### Textbringer integration
65
+
66
+ ```ruby
67
+ define_command(:copy_permanent_uri, doc: "Copy permanent URI") do
68
+ require "dpu"
69
+ b = Buffer.current
70
+ uri = Dpu.determine_permanent_uri(Pathname(b.file_name), b.current_line)
71
+ KILL_RING.push(uri)
72
+ Clipboard.copy(uri) if CLIPBOARD_AVAILABLE
73
+ message("Copied: #{uri}")
74
+ end
75
+
76
+ GLOBAL_MAP.define_key("\C-xL", :copy_permanent_uri)
77
+ ```
78
+
34
79
  ## Contributing
35
80
 
36
81
  Bug reports and pull requests are welcome on GitHub at https://github.com/nishidayuya/dpu .
data/Rakefile CHANGED
@@ -1,4 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "bundler/gem_tasks"
4
- task default: %i[]
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << "test"
8
+ t.test_files = FileList["test/**/*_test.rb"]
9
+ end
10
+
11
+ task(default: %i[test])
data/lib/dpu/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dpu
4
- VERSION = "0.1.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/dpu.rb CHANGED
@@ -8,8 +8,16 @@ module Dpu
8
8
 
9
9
  class << self
10
10
  GITHUB_REPOSITORY_URI_TEMPLATE = "https://github.com/%{account_name}/%{repository_name}"
11
+ REMOTE_URL_PATTERN = [
12
+ %r{\Agit://github\.com/(?<account_name>[^/]+)/(?<repository_name>.+)(?=\.git)},
13
+ %r{\Ahttps?://github\.com/(?<account_name>[^/]+)/(?<repository_name>.+)(?=\.git)},
14
+ %r{\Agit@github\.com:(?<account_name>[^/]+)/(?<repository_name>.+)(?=\.git)},
15
+ %r{\Assh://git@github\.com/(?<account_name>[^/]+)/(?<repository_name>.+)(?=\.git)},
16
+ ].then { |patterns|
17
+ Regexp.union(*patterns)
18
+ }
11
19
 
12
- def determine_permanent_uri(path, start_line_number, end_line_number)
20
+ def determine_permanent_uri(path, start_line_number = nil, end_line_number = nil)
13
21
  relative_path = determine_relative_path(path)
14
22
 
15
23
  permanent_uri_parts = [
@@ -44,14 +52,16 @@ module Dpu
44
52
  stdout = run_command("git remote get-url origin", chdir: path.dirname)
45
53
  repository_http_or_ssh_url = stdout.chomp
46
54
 
47
- md = %r{\Agit@github\.com:(?<account_name>[^/]+)/(?<repository_name>.+)(?=\.git)}.match(repository_http_or_ssh_url)
55
+ md = REMOTE_URL_PATTERN.match(repository_http_or_ssh_url)
48
56
  if !md
49
57
  return URI(repository_http_or_ssh_url)
50
58
  end
51
59
 
52
- md => {account_name:, repository_name:}
53
- url = GITHUB_REPOSITORY_URI_TEMPLATE % {account_name:, repository_name:}
54
- URI(url)
60
+ url = GITHUB_REPOSITORY_URI_TEMPLATE % {
61
+ account_name: md[:account_name],
62
+ repository_name: md[:repository_name],
63
+ }
64
+ return URI(url)
55
65
  end
56
66
 
57
67
  def determine_commit_id(path)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dpu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuya.Nishida.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-05-14 00:00:00.000000000 Z
11
+ date: 2023-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: debug
@@ -24,7 +24,21 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- description:
27
+ - !ruby/object:Gem::Dependency
28
+ name: test-unit
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
+ description:
28
42
  email:
29
43
  - yuya@j96.org
30
44
  executables:
@@ -46,7 +60,7 @@ licenses: []
46
60
  metadata:
47
61
  homepage_uri: https://github.com/nishidayuya/dpu
48
62
  source_code_uri: https://github.com/nishidayuya/dpu
49
- post_install_message:
63
+ post_install_message:
50
64
  rdoc_options: []
51
65
  require_paths:
52
66
  - lib
@@ -62,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
76
  version: '0'
63
77
  requirements: []
64
78
  rubygems_version: 3.4.10
65
- signing_key:
79
+ signing_key:
66
80
  specification_version: 4
67
81
  summary: determine permanent URI
68
82
  test_files: []