trk 0.1.4 → 0.1.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7c38302d31fd705e553d2596b8c6e878a95f81b4a49d15bb044354a930d1fe2d
4
- data.tar.gz: 0aae3f6637ac5838c776c590877ad2a67f4581302525ef510612a969a56cd6f0
3
+ metadata.gz: aadec329696267ada6db94f0d871454eece18090a4566e3a6f9684c406e48db6
4
+ data.tar.gz: c2a28757d21a24d0197332ca50c30aa36bf2a69de43accd5e54c550ca8b3b695
5
5
  SHA512:
6
- metadata.gz: 44390e4ab9e14328dda5c05645bc1c7e2eb74ee6c32a7a6a962edd06fe1f9c1f6f4c2a28dadc312cbdbb4690173c73529bc84cccdd65e3e20e380bb0d671852d
7
- data.tar.gz: 0daa1839615e15d522ae3d6c48608d3f5ec24f055ab6c79d89809696c6e6773bbc9fe68891cf9e0f9fe4e583084f3580288aec97edc879cb27fd2ce6f7ed766a
6
+ metadata.gz: 6d0ed0b289b76acbf65269be76b22a5ad8ea2284e38dbe0a04b48e221a7b17343b80b4df496a2b0dfe3f24e2f8971a0fcedee50490fe7d94c3916db88316edaf
7
+ data.tar.gz: 9cde2261c3bad6236099fce1901cb0d5e63965073f3557f1400f7dec939f33922d28399643c14b5e36ecf14d88ab58dca2c74139667ae9c3bca6cc38cbfd6f0e
data/README.md CHANGED
@@ -17,16 +17,42 @@ mkdir ~/trk
17
17
 
18
18
  ### Links for code in README
19
19
 
20
- For code that is written only in README file we need to wrap with
21
- `This code is from: link` where link is a repo path with an anchor to
22
- subheader `#sub-header`, and finish with `End of code from: link`
20
+ For a single line or for complete file we can use comment
21
+ ```
22
+ # This code is from: https://trk.tools/app/trk-readme-source-links/-/blob/main/README.md
23
+ ```
24
+
25
+ When a part of the file is extracted from trk.tools we can use `Start` and `End
26
+ of code from:`
27
+
23
28
  ```
24
29
  # .bashrc
25
- # This code is from: https://trk.tools/app/trk-readme-source-links#links-for-code-in-readme
30
+ # Start of code from: https://trk.tools/app/trk-readme-source-links#links-for-code-in-readme
26
31
  ...
27
32
  # End of code from: https://trk.tools/app/trk-readme-source-links#links-for-code-in-readme
28
33
  ```
29
34
 
35
+ For download use `wget` and `raw` instead of `blob`
36
+ ```
37
+ # wget -P path https://trk.tools/app/trk-readme-source-links/-/raw/main/README.md
38
+ ```
39
+
40
+ Using this gem you can get the string with
41
+ ```
42
+ trk link-show
43
+ ```
44
+
45
+ For vim you can use mapping
46
+ ```
47
+ # .vimrc
48
+ nnoremap <leader>s :r !trk link-show %<CR>
49
+
50
+ # local gem
51
+ nnoremap <leader>s :r !cd ~/trk.tools/app/trk-readme-source-links && bundle exec exe/trk link-show %:p<CR>
52
+ nnoremap <leader>e :r !cd ~/trk.tools/app/trk-readme-source-links && bundle exec exe/trk link-show-end %:p<CR>
53
+ nnoremap <leader>r :r !cd ~/trk.tools/app/trk-readme-source-links && bundle exec exe/trk link-show-raw %:p<CR>
54
+ ```
55
+
30
56
  ### Links for code in other files
31
57
 
32
58
  For other files we need to link to specific file
@@ -62,9 +88,39 @@ Run without installing the gem
62
88
  bundle exec exe/trk pull
63
89
  ```
64
90
 
65
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
91
+ After checking out the repo, run `bin/setup` to install dependencies.
92
+ You can also run `bin/console` for an interactive prompt that will allow you to experiment.
66
93
 
67
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
94
+ To put a debugger use
95
+ ```
96
+ binding.break
97
+ ```
98
+
99
+ ## Test
100
+
101
+ To run all tests
102
+ ```
103
+ rake test
104
+ ```
105
+ To run single file
106
+ ```
107
+ ruby -Itest test/test_link.rb
108
+ ```
109
+ or single test
110
+ ```
111
+ ruby -Itest test/test_link.rb --name test_link_show_success
112
+ ```
113
+
114
+ ## Gem push
115
+
116
+ To install this gem onto your local machine, run `bundle exec rake install`.
117
+ To release a new version, update the version number in `lib/trk/version.rb`, and
118
+ then deploy with:
119
+ ```
120
+ bundle exec rake release
121
+ ```
122
+ which will create a git tag for the version, push git commits and the created
123
+ tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
68
124
 
69
125
  ## Contributing
70
126
 
data/lib/trk/cli.rb CHANGED
@@ -2,6 +2,7 @@ require "thor"
2
2
  require "open3"
3
3
  require "net/http"
4
4
  require "uri"
5
+ require "debug"
5
6
 
6
7
  module Trk
7
8
  class CLI < Thor
@@ -15,8 +16,8 @@ module Trk
15
16
 
16
17
  def self.help(shell, subcommand = false)
17
18
  super
18
- puts "\n To enable autocomplete, put in .bashrc: 'complete -W \"$(trk completion)\" trk', eg:\n"
19
- puts "echo '# https://trk.tools/app/trk-readme-source-links\ncomplete -W \"$(trk completion)\" trk' >> ~/.bashrc && source ~/.bashrc"
19
+ puts "\nTo enable autocomplete, put in .bashrc following two lines:"
20
+ puts "# https://trk.tools/app/trk-readme-source-links\ntrk completion > /dev/null 2>&1 && complete -W \"$(trk completion)\" trk"
20
21
  end
21
22
 
22
23
  desc "completion", "Outputs available commands for autocompletion"
@@ -75,5 +76,61 @@ module Trk
75
76
 
76
77
  puts "\n#{CHECK_ICON} All done!"
77
78
  end
79
+
80
+ desc "link-show FILENAME", "Show start link of the file"
81
+ def link_show(filename)
82
+ result = Link.new(filename).show
83
+ if result.success?
84
+ # puts "#{CHECK_ICON} link done #{result.message}\n#{result.data[:link]}"
85
+ puts result.data[:link]
86
+ else
87
+ puts "#{UNCHECK_ICON} link failed\n#{result.message}"
88
+ end
89
+ end
90
+
91
+ desc "link-show-end FILENAME", "Show end link of the file"
92
+ def link_show_end(filename)
93
+ result = Link.new(filename).show_end
94
+ if result.success?
95
+ # puts "#{CHECK_ICON} link done #{result.message}\n#{result.data[:link]}"
96
+ puts result.data[:link]
97
+ else
98
+ puts "#{UNCHECK_ICON} link failed\n#{result.message}"
99
+ end
100
+ end
101
+
102
+ desc "link-show-raw FILENAME", "Show wget link of the file"
103
+ def link_show_raw(filename)
104
+ result = Link.new(filename).raw
105
+ if result.success?
106
+ # puts "#{CHECK_ICON} link done #{result.message}\n#{result.data[:link]}"
107
+ puts result.data[:link]
108
+ else
109
+ puts "#{UNCHECK_ICON} link failed\n#{result.message}"
110
+ end
111
+ end
112
+
113
+ desc "sos", "Add sos script to .bashrc if not already there"
114
+ def sos(*arguments)
115
+ command = <<~HERE_DOC
116
+ # Start of code: https://trk.tools/sh/screen-tips#remote-multiuser-access-help-using-ssh-and-gnu-screen
117
+ # remote version
118
+ sos() { sos_user=$1 sos_port=$2 sos_host=h2.trk.tools bash <(curl -sL sos.trk.tools) ;}
119
+ # local version
120
+ # sos() { sos_user=$1 sos_port=$2 sos_host=h2.trk.tools ~/trk.tools/sh/screen-tips/remote_multiuser_access_help_using_ssh_and_gnu_screen.sh ;}
121
+ # End of code: https://trk.tools/sh/screen-tips#remote-multiuser-access-help-using-ssh-and-gnu-screen
122
+ HERE_DOC
123
+ bashrc_path = File.expand_path("~/.bashrc")
124
+ bashrc_content = File.read(bashrc_path) if File.exist?(bashrc_path)
125
+ if bashrc_content&.include?("sos()")
126
+ puts "#{UNCHECK_ICON} sos already exists in .bashrc"
127
+ else
128
+ File.open(bashrc_path, "a") do |file|
129
+ file.puts
130
+ file.puts command
131
+ end
132
+ puts "#{CHECK_ICON} sos function added to .bashrc, please open new terminal, or run: source ~/.bashrc"
133
+ end
134
+ end
78
135
  end
79
136
  end
data/lib/trk/link.rb ADDED
@@ -0,0 +1,49 @@
1
+ module Trk
2
+ class Link
3
+ BASE_URL = "https://trk.tools"
4
+ BRANCH_PREFIX = "-/blob/main/"
5
+ BRANCH_RAW_PREFIX = "-/raw/main/"
6
+ THIS_CODE_IS_FROM = "This code is from:"
7
+ START_OF_CODE_FROM = "Start of code from:"
8
+ END_OF_CODE_FROM = "End of code from:"
9
+ WGET = "# wget -P"
10
+
11
+ def initialize(filename = nil)
12
+ @filename = filename
13
+ end
14
+
15
+ def show
16
+ full_path = File.absolute_path?(@filename) ? @filename : File.expand_path(@filename) # /Volumes/ONETB/dule/trk.tools/app/trk-readme-source-links/test/test_link.rb
17
+ folders_from_trk_tools = full_path.sub(/.*trk.tools\//, "")
18
+ return Error.new "File #{@filename} is not inside trk.tools" if full_path == folders_from_trk_tools
19
+
20
+ repo_path = folders_from_trk_tools.split("/")[0..1].join("/")
21
+ file_path = folders_from_trk_tools.split("/")[2..].join("/")
22
+ link = "# #{START_OF_CODE_FROM} #{BASE_URL}/#{repo_path}/#{BRANCH_PREFIX}#{file_path}"
23
+ Result.new "OK", link: link
24
+ end
25
+
26
+ def show_end
27
+ full_path = File.absolute_path?(@filename) ? @filename : File.expand_path(@filename) # /Volumes/ONETB/dule/trk.tools/app/trk-readme-source-links/test/test_link.rb
28
+ folders_from_trk_tools = full_path.sub(/.*trk.tools\//, "")
29
+ return Error.new "File #{@filename} is not inside trk.tools" if full_path == folders_from_trk_tools
30
+
31
+ repo_path = folders_from_trk_tools.split("/")[0..1].join("/")
32
+ file_path = folders_from_trk_tools.split("/")[2..].join("/")
33
+ link = "# #{END_OF_CODE_FROM} #{BASE_URL}/#{repo_path}/#{BRANCH_PREFIX}#{file_path}"
34
+ Result.new "OK", link: link
35
+ end
36
+
37
+ def raw
38
+ full_path = File.absolute_path?(@filename) ? @filename : File.expand_path(@filename) # /Volumes/ONETB/dule/trk.tools/app/trk-readme-source-links/test/test_link.rb
39
+ folders_from_trk_tools = full_path.sub(/.*trk.tools\//, "")
40
+ return Error.new "File #{@filename} is not inside trk.tools" if full_path == folders_from_trk_tools
41
+
42
+ repo_path = folders_from_trk_tools.split("/")[0..1].join("/")
43
+ file_path = folders_from_trk_tools.split("/")[2..].join("/")
44
+ file_folder = folders_from_trk_tools.split("/")[2..-2].join("/") || "."
45
+ link = "#{WGET} #{file_folder} #{BASE_URL}/#{repo_path}/#{BRANCH_RAW_PREFIX}#{file_path}"
46
+ Result.new "OK", link: link
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,42 @@
1
+ class Result
2
+ attr_accessor :message, :data
3
+
4
+ # Use this to class to return results from service:
5
+ #
6
+ # class MyService
7
+ # def perform
8
+ # if true
9
+ # Result.new "Next task created", next_task: next_task
10
+ # else
11
+ # Error.new "Failed"
12
+ # end
13
+ # end
14
+ # end
15
+ #
16
+ # and use in controller:
17
+ #
18
+ # result = MyService.new.perform
19
+ # if result.success?
20
+ # flash[:notice] = result.message
21
+ # redirect_to result.data[:next_task]
22
+ # end
23
+ #
24
+ # Note when iterating a huge objects, use `next_task_id` so Ruby Garbage
25
+ # Collector can clear all temp objects from the service run
26
+ # If you return some object which is not basic, it can not safely clear all
27
+ # temp objects
28
+ #
29
+ def initialize(message, data = {})
30
+ @message, @data = message, data
31
+ end
32
+
33
+ def success?
34
+ true
35
+ end
36
+ end
37
+
38
+ class Error < Result
39
+ def success?
40
+ false
41
+ end
42
+ end
data/lib/trk/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Trk
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.7"
5
5
  CHECK_ICON = "✅ "
6
6
  UNCHECK_ICON = "❌ "
7
7
  end
data/lib/trk.rb CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  require_relative "trk/version"
4
4
  require_relative "trk/cli"
5
+ require_relative "trk/link"
6
+ require_relative "trk/result_and_error"
5
7
 
6
8
  module Trk
7
- class Error < StandardError; end
8
- # Your code goes here...
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dusan Orlovic
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-03-11 00:00:00.000000000 Z
11
+ date: 2025-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -41,6 +41,8 @@ files:
41
41
  - exe/trk
42
42
  - lib/trk.rb
43
43
  - lib/trk/cli.rb
44
+ - lib/trk/link.rb
45
+ - lib/trk/result_and_error.rb
44
46
  - lib/trk/version.rb
45
47
  - sig/trk.rbs
46
48
  homepage: https://trk.tools
@@ -57,7 +59,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
57
59
  requirements:
58
60
  - - ">="
59
61
  - !ruby/object:Gem::Version
60
- version: 3.0.0
62
+ version: 3.0.1
61
63
  required_rubygems_version: !ruby/object:Gem::Requirement
62
64
  requirements:
63
65
  - - ">="