trk 0.1.3 → 0.1.6

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: 3da7a8df4179a04353de1da8f56b71fd084ea0b7323509669a033b5bbe0cd427
4
- data.tar.gz: dcfe27b52720e39081f6c834e8b98becd7b142ccd033da7c59844c1ad10aa737
3
+ metadata.gz: daa75cf6eea07a201c466b5d8d18bf320ed898bf9458d94345b8481a0b9ec110
4
+ data.tar.gz: d1698a006089a9e4a49b6d63efed1aace33a9bdd9a311f99e6014e14994e5a26
5
5
  SHA512:
6
- metadata.gz: 40d509303d7f61454e4d9c369c7600e7b6626bb2775160a27c69f2afe7709a4b256d393d4169592f791f7b8cdfba0b90ea88e151a1cc5c6bd532640214ea1241
7
- data.tar.gz: 17d7a7f32106d78233e56a426d86000f7b08d53a6f161de9bc5d073409c7640eff887d15a9ace02434cff9019f232c60e0c691ea51b1937c37718104f8023381
6
+ metadata.gz: 0d77302b31fe36f291dd222e777de1f3f05999e8b67b03288296817e2e81e596017fe9a73507f5f89697e269c08e570eed3597774d0e2860ee163e00d607e574
7
+ data.tar.gz: ea4d57c56eb0edffc2498a10780b3f797d3d75f1b0c57a34b512dd01cf762111a7c6630a7cdcc683f71b866d73d317f9dfb54e68eadc8492aa9796833e85a8bc
data/README.md CHANGED
@@ -17,16 +17,41 @@ 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 complete file
21
+ ```
22
+ # This code is from: https://trk.tools/app/trk-readme-source-links/-/blob/main/README.md
23
+ ```
24
+
25
+ When only a part of the file is extracted from trk.tools use Start and End of
26
+ code
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>r :r !cd ~/trk.tools/app/trk-readme-source-links && bundle exec exe/trk link-show-raw %:p<CR>
53
+ ```
54
+
30
55
  ### Links for code in other files
31
56
 
32
57
  For other files we need to link to specific file
@@ -62,9 +87,39 @@ Run without installing the gem
62
87
  bundle exec exe/trk pull
63
88
  ```
64
89
 
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.
90
+ After checking out the repo, run `bin/setup` to install dependencies.
91
+ You can also run `bin/console` for an interactive prompt that will allow you to experiment.
66
92
 
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).
93
+ To put a debugger use
94
+ ```
95
+ binding.break
96
+ ```
97
+
98
+ ## Test
99
+
100
+ To run all tests
101
+ ```
102
+ rake test
103
+ ```
104
+ To run single file
105
+ ```
106
+ ruby -Itest test/test_link.rb
107
+ ```
108
+ or single test
109
+ ```
110
+ ruby -Itest test/test_link.rb --name test_link_show_success
111
+ ```
112
+
113
+ ## Gem push
114
+
115
+ To install this gem onto your local machine, run `bundle exec rake install`.
116
+ To release a new version, update the version number in `lib/trk/version.rb`, and
117
+ then deploy with:
118
+ ```
119
+ bundle exec rake release
120
+ ```
121
+ which will create a git tag for the version, push git commits and the created
122
+ tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
68
123
 
69
124
  ## Contributing
70
125
 
data/lib/trk/cli.rb CHANGED
@@ -2,9 +2,29 @@ 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
9
+ def self.start(given_args = ARGV, config = {})
10
+ if given_args.include?("--version") || given_args.include?("-v")
11
+ puts "trk version #{VERSION}"
12
+ exit
13
+ end
14
+ super
15
+ end
16
+
17
+ def self.help(shell, subcommand = false)
18
+ super
19
+ puts "\n To enable autocomplete, put in .bashrc: 'complete -W \"$(trk completion)\" trk', eg:\n"
20
+ puts "echo '# https://trk.tools/app/trk-readme-source-links\ncomplete -W \"$(trk completion)\" trk' >> ~/.bashrc && source ~/.bashrc"
21
+ end
22
+
23
+ desc "completion", "Outputs available commands for autocompletion"
24
+ def completion
25
+ puts self.class.all_commands.keys.join(" ")
26
+ end
27
+
8
28
  desc "add_github_keys USERNAME", "Add Github user public keys to .ssh/authorized_keys"
9
29
  def add_github_keys(username)
10
30
  uri = URI "https://trk.tools/sh/ssh-tips/-/raw/main/add_github_keys_to_authorized_keys.sh"
@@ -56,5 +76,50 @@ module Trk
56
76
 
57
77
  puts "\n#{CHECK_ICON} All done!"
58
78
  end
79
+
80
+ desc "link-show FILENAME", "Show 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-raw FILENAME", "Show wget link of the file"
92
+ def link_show_raw(filename)
93
+ result = Link.new(filename).raw
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 "sos", "Add sos script to .bashrc if not already there"
103
+ def sos(*arguments)
104
+ command = <<~HERE_DOC
105
+ # Start of code: https://trk.tools/sh/screen-tips#remote-multiuser-access-help-using-ssh-and-gnu-screen
106
+ # remote version
107
+ sos() { sos_user=$1 sos_port=$2 sos_host=h2.trk.tools bash <(curl -sL sos.trk.tools) ;}
108
+ # local version
109
+ # 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 ;}
110
+ # End of code: https://trk.tools/sh/screen-tips#remote-multiuser-access-help-using-ssh-and-gnu-screen
111
+ HERE_DOC
112
+ bashrc_path = File.expand_path("~/.bashrc")
113
+ bashrc_content = File.read(bashrc_path) if File.exist?(bashrc_path)
114
+ if bashrc_content&.include?("sos()")
115
+ puts "#{UNCHECK_ICON} sos already exists in .bashrc"
116
+ else
117
+ File.open(bashrc_path, "a") do |file|
118
+ file.puts
119
+ file.puts command
120
+ end
121
+ puts "#{CHECK_ICON} sos function added to .bashrc, please open new terminal, or run: source ~/.bashrc"
122
+ end
123
+ end
59
124
  end
60
125
  end
data/lib/trk/link.rb ADDED
@@ -0,0 +1,40 @@
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)
17
+ home_path = Dir.home
18
+ folders_from_home = full_path.sub(/^#{Regexp.escape(home_path)}\//, "").split("/")
19
+ return Error.new "File #{@filename} is not inside ~/trk.tools" unless folders_from_home.first == "trk.tools"
20
+
21
+ repo_path = folders_from_home[1..2].join("/")
22
+ file_path = folders_from_home[3..].join("/")
23
+ link = "# #{THIS_CODE_IS_FROM} #{BASE_URL}/#{repo_path}/#{BRANCH_PREFIX}#{file_path}"
24
+ Result.new "OK", link: link
25
+ end
26
+
27
+ def raw
28
+ full_path = File.absolute_path?(@filename) ? @filename : File.expand_path(@filename)
29
+ home_path = Dir.home
30
+ folders_from_home = full_path.sub(/^#{Regexp.escape(home_path)}\//, "").split("/")
31
+ return Error.new "File #{@filename} is not inside ~/trk.tools" unless folders_from_home.first == "trk.tools"
32
+
33
+ repo_path = folders_from_home[1..2].join("/")
34
+ file_path = folders_from_home[3..].join("/")
35
+ file_folder = folders_from_home[3..-2].join("/") || "."
36
+ link = "#{WGET} #{file_folder} #{BASE_URL}/#{repo_path}/#{BRANCH_RAW_PREFIX}#{file_path}"
37
+ Result.new "OK", link: link
38
+ end
39
+ end
40
+ 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.3"
4
+ VERSION = "0.1.6"
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,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dusan Orlovic
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2025-03-11 00:00:00.000000000 Z
10
+ date: 2025-03-17 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: thor
@@ -41,6 +40,8 @@ files:
41
40
  - exe/trk
42
41
  - lib/trk.rb
43
42
  - lib/trk/cli.rb
43
+ - lib/trk/link.rb
44
+ - lib/trk/result_and_error.rb
44
45
  - lib/trk/version.rb
45
46
  - sig/trk.rbs
46
47
  homepage: https://trk.tools
@@ -49,7 +50,6 @@ licenses:
49
50
  metadata:
50
51
  homepage_uri: https://trk.tools
51
52
  source_code_uri: https://trk.tools/app/trk-readme-source-links
52
- post_install_message:
53
53
  rdoc_options: []
54
54
  require_paths:
55
55
  - lib
@@ -64,8 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
64
  - !ruby/object:Gem::Version
65
65
  version: '0'
66
66
  requirements: []
67
- rubygems_version: 3.5.16
68
- signing_key:
67
+ rubygems_version: 3.6.2
69
68
  specification_version: 4
70
69
  summary: CLI tools to manipulate https://trk.tools README files and projects.
71
70
  test_files: []