trk 0.1.4 → 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 +4 -4
- data/README.md +61 -6
- data/lib/trk/cli.rb +46 -0
- data/lib/trk/link.rb +40 -0
- data/lib/trk/result_and_error.rb +42 -0
- data/lib/trk/version.rb +1 -1
- data/lib/trk.rb +2 -2
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: daa75cf6eea07a201c466b5d8d18bf320ed898bf9458d94345b8481a0b9ec110
|
4
|
+
data.tar.gz: d1698a006089a9e4a49b6d63efed1aace33a9bdd9a311f99e6014e14994e5a26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
21
|
-
|
22
|
-
|
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
|
-
#
|
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.
|
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
|
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,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
|
@@ -75,5 +76,50 @@ module Trk
|
|
75
76
|
|
76
77
|
puts "\n#{CHECK_ICON} All done!"
|
77
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
|
78
124
|
end
|
79
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
data/lib/trk.rb
CHANGED
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.
|
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-
|
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.
|
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: []
|