gpt_helpr 0.2.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 +7 -0
- data/README.md +119 -0
- data/bin/console +8 -0
- data/bin/gpt_helpr +5 -0
- data/bin/lmk +5 -0
- data/bin/setup +8 -0
- data/lib/gpt_helpr/cli.rb +127 -0
- data/lib/gpt_helpr/version.rb +5 -0
- data/lib/gpt_helpr.rb +8 -0
- metadata +72 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 517f6f3290d45ea8b2e9b14e6c77d051ae771948c2f1b37d39ddc27a891d624f
|
4
|
+
data.tar.gz: ab65c67d108926f07ecd777ec3ddfce14192d1a975c76da18ed59f919ee7095f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d04bcfee6aface86e18e757d5e2427ce048d9bf5f06190fd708353de915477598f14f0459a8d53a5a9cebeb80e01b0b0bf0a2b6a549b6ec78b7cade7e9ce7bba
|
7
|
+
data.tar.gz: 2a4036ccdd1b35bba237c55433c69924b22dc11f6fd28b5e0de4fc98d9f7f97da3759a01f74b653d37f29da693c24b4770d00d7122e36957ab4cc308446cce0b
|
data/README.md
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
# GPT_Helpr
|
2
|
+
|
3
|
+
GPT_Helpr is a Ruby gem that provides a command-line tool for generating formatted programming prompts based on the content of specified files. This tool is particularly useful for efficiently sharing code snippets with detailed explanations.
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
- **Interactive Mode**: Easily specify file paths and ranges interactively.
|
8
|
+
- **Line Numbers**: Option to include line numbers in the output.
|
9
|
+
- **Completion Support**: Supports tab completion for file paths.
|
10
|
+
- **Output to File**: Option to write the generated output to a file.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
1. **Add the Gem to Your Gemfile**
|
15
|
+
```ruby
|
16
|
+
gem 'gpt_helpr'
|
17
|
+
```
|
18
|
+
|
19
|
+
2. **Install the Gem**
|
20
|
+
```sh
|
21
|
+
bundle install
|
22
|
+
```
|
23
|
+
|
24
|
+
3. **Or Install Directly via Gem Command**
|
25
|
+
```sh
|
26
|
+
gem install gpt_helpr
|
27
|
+
```
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
### Basic Usage
|
32
|
+
|
33
|
+
Run the tool in interactive mode:
|
34
|
+
```sh
|
35
|
+
gpt_helpr --interactive
|
36
|
+
```
|
37
|
+
|
38
|
+
### Command-Line Arguments
|
39
|
+
|
40
|
+
You can also provide file paths and instructions directly via command-line arguments:
|
41
|
+
```sh
|
42
|
+
gpt_helpr <file1> <re: instructions> / <file2> <re: instructions>
|
43
|
+
```
|
44
|
+
|
45
|
+
### Options
|
46
|
+
|
47
|
+
- `--interactive` or `-i`: Run the tool in interactive mode.
|
48
|
+
- `--file` or `-f`: Write the output to a file.
|
49
|
+
- `--line-numbers` or `-ln`: Include line numbers in the output.
|
50
|
+
|
51
|
+
### Examples
|
52
|
+
|
53
|
+
#### Interactive Mode
|
54
|
+
|
55
|
+
1. Run the tool:
|
56
|
+
|
57
|
+
```
|
58
|
+
➜ gpt_helpr -i -ln
|
59
|
+
File path (optional :start:end): TAB ->
|
60
|
+
Capfile INSTALL.md REVISION bin
|
61
|
+
Gemfile Procfile Rakefile config
|
62
|
+
Gemfile.lock Procfile.dev VERSION config.ru
|
63
|
+
Guardfile README.md app db
|
64
|
+
|
65
|
+
File path (optional :start:end): bin/ TAB ->
|
66
|
+
bin/bundle bin/db-backup.sh bin/db-restore.sh bin/gpt_helpr bin/rails bin/rake bin/rubocop bin/s3_sync.sh bin/setup bin/update
|
67
|
+
|
68
|
+
File path (optional :start:end): bin/gpt_helpr:9:14
|
69
|
+
Instructions: can you explain these lines?
|
70
|
+
File path (optional :start:end):
|
71
|
+
```
|
72
|
+
|
73
|
+
2. The output will be:
|
74
|
+
```
|
75
|
+
#### file source `bin/gpt_helpr`
|
76
|
+
9:
|
77
|
+
10: Readline.completion_append_character = nil
|
78
|
+
11: Readline.completion_proc = -> (input) {
|
79
|
+
12: Dir[input+'*'].grep(/^#{Regexp.escape(input)}/)
|
80
|
+
13: }
|
81
|
+
14:
|
82
|
+
|
83
|
+
can you explain these lines?
|
84
|
+
|
85
|
+
#### end of `bin/gpt_helpr`
|
86
|
+
```
|
87
|
+
3. You can add more files and instructions in the same way.
|
88
|
+
|
89
|
+
4. The output will be also copied to the clipboard!
|
90
|
+
|
91
|
+
#### Command-Line Mode
|
92
|
+
|
93
|
+
1. Generate output for specified files:
|
94
|
+
```sh
|
95
|
+
gpt_helpr app/controllers/pos_controller.rb:10:20 "Describe the controller logic" / app/views/pos/index.html.erb "Explain the view template"
|
96
|
+
```
|
97
|
+
|
98
|
+
2. Write the output to a file:
|
99
|
+
```sh
|
100
|
+
gpt_helpr app/controllers/pos_controller.rb:10:20 "Describe the controller logic" / app/views/pos/index.html.erb "Explain the view template" --file
|
101
|
+
```
|
102
|
+
|
103
|
+
## Why GPT_Helpr?
|
104
|
+
|
105
|
+
GPT_Helpr is designed to save time and effort when sharing code snippets. It's often necessary to provide context and explanations for the code. Instead of manually copying and formatting code snippets, GPT_Helpr automates the process, generating well-structured Markdown output.
|
106
|
+
|
107
|
+
This can be useful for:
|
108
|
+
|
109
|
+
- **Creating Documentation**: Quickly generate descriptions of code segments for documentation.
|
110
|
+
- **Sharing Code**: Share specific parts of your codebase with clear descriptions.
|
111
|
+
- **Teaching and Learning**: Provide examples and explanations of code in a consistent format.
|
112
|
+
|
113
|
+
## Contributing
|
114
|
+
|
115
|
+
Contributions are welcome! If you have suggestions for improvements or find any issues, please open an issue or create a pull request.
|
116
|
+
|
117
|
+
## License
|
118
|
+
|
119
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
data/bin/console
ADDED
data/bin/gpt_helpr
ADDED
data/bin/lmk
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'readline'
|
3
|
+
require 'shellwords'
|
4
|
+
require 'time'
|
5
|
+
|
6
|
+
module GptHelpr
|
7
|
+
class CLI
|
8
|
+
|
9
|
+
def self.start(args=[])
|
10
|
+
Dir.chdir(Dir.pwd)
|
11
|
+
|
12
|
+
puts "GptHelpr #{GptHelpr::VERSION} - To help dig your codebase and cook GPT-XX instructions [current directory #{Dir.pwd}]"
|
13
|
+
line_numbers = args.include?('-ln') || args.include?('--line-numbers')
|
14
|
+
|
15
|
+
if args.include?('-i') || args.include?('--interactive')
|
16
|
+
files = interactive_mode(line_numbers)
|
17
|
+
else
|
18
|
+
|
19
|
+
if args.empty?
|
20
|
+
puts 'Usage: gpt_helpr <file1> <re: instructions> / <file2> <re: instructions> [--f] [--file] [--i] [--interactive] [--ln] [--line-numbers]'
|
21
|
+
exit 1
|
22
|
+
end
|
23
|
+
|
24
|
+
separator_indices = args.each_index.select { |i| args[i] == '/' }
|
25
|
+
parts = []
|
26
|
+
last_index = 0
|
27
|
+
|
28
|
+
separator_indices.each do |index|
|
29
|
+
parts << args[last_index...index]
|
30
|
+
last_index = index + 1
|
31
|
+
end
|
32
|
+
parts << args[last_index..]
|
33
|
+
|
34
|
+
files = parts.map do |part|
|
35
|
+
file_path = part[0]
|
36
|
+
re_text = part[1]
|
37
|
+
lines_range = file_path.include?(':') ? file_path.split(':', 2).last : nil
|
38
|
+
file_path = file_path.split(':').first
|
39
|
+
|
40
|
+
[file_path, re_text, lines_range]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
final_output = generate_output(files, line_numbers)
|
45
|
+
copy_to_clipboard(final_output)
|
46
|
+
|
47
|
+
if args.include?('-f') || args.include?('--file')
|
48
|
+
write_to_file(final_output)
|
49
|
+
else
|
50
|
+
puts final_output
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.process_file(file_path, lines_range = nil, line_numbers = false)
|
55
|
+
content = File.read(file_path)
|
56
|
+
|
57
|
+
if lines_range
|
58
|
+
start_line, end_line = lines_range.split(':').map(&:to_i)
|
59
|
+
content = content.lines[start_line - 1, end_line - start_line + 1].join
|
60
|
+
end
|
61
|
+
|
62
|
+
if line_numbers
|
63
|
+
start_index = lines_range ? start_line : 1
|
64
|
+
content = content.lines.each_with_index.map { |line, index| "#{start_index + index}: #{line}" }.join
|
65
|
+
end
|
66
|
+
|
67
|
+
content
|
68
|
+
rescue => e
|
69
|
+
"Error reading file: #{e.message}"
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.generate_output(files, line_numbers = false)
|
73
|
+
output = ''
|
74
|
+
files.each do |file_info|
|
75
|
+
file_path, re_text, lines_range = file_info
|
76
|
+
|
77
|
+
content = process_file(file_path, lines_range, line_numbers)
|
78
|
+
|
79
|
+
output += "#### file source `#{file_path}`\n"
|
80
|
+
output += "```\n"
|
81
|
+
output += "#{content}\n"
|
82
|
+
output += "```\n\n"
|
83
|
+
output += "#{re_text}\n\n"
|
84
|
+
output += "#### end of `#{file_path}`\n"
|
85
|
+
output += "\n"
|
86
|
+
end
|
87
|
+
output
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.copy_to_clipboard(output)
|
91
|
+
escaped_output = Shellwords.escape(output)
|
92
|
+
system("echo #{escaped_output} | pbcopy")
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.write_to_file(output)
|
96
|
+
timestamp = Time.now.utc.iso8601
|
97
|
+
filename = "gpt_#{timestamp}.md"
|
98
|
+
File.write(filename, output)
|
99
|
+
puts "Output written to #{filename}"
|
100
|
+
end
|
101
|
+
|
102
|
+
def self.interactive_mode(line_numbers = false)
|
103
|
+
files = []
|
104
|
+
|
105
|
+
Readline.completion_append_character = nil
|
106
|
+
Readline.completion_proc = -> (input) {
|
107
|
+
Dir[input + '*'].grep(/^#{Regexp.escape(input)}/)
|
108
|
+
}
|
109
|
+
|
110
|
+
while true
|
111
|
+
begin
|
112
|
+
file_input = Readline.readline('File Path (optional :start:end): ', true)
|
113
|
+
break if file_input.nil? || file_input.strip.empty?
|
114
|
+
|
115
|
+
file_path, lines_range = file_input.split(':', 2)
|
116
|
+
re_text = Readline.readline('Instructions: ', true)
|
117
|
+
|
118
|
+
files << [file_path.strip, re_text.strip, lines_range]
|
119
|
+
rescue Interrupt
|
120
|
+
break
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
files
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
data/lib/gpt_helpr.rb
ADDED
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gpt_helpr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Emanuele Tozzato
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-07-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: readline
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.0.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.0.3
|
27
|
+
description: It is often necessary to provide context and explanations for the code.
|
28
|
+
Instead of manually copying and formatting code snippets, GPT-Helpr automates the
|
29
|
+
process, generating well-structured Markdown output.
|
30
|
+
email:
|
31
|
+
- etozzato@gmail.com
|
32
|
+
executables:
|
33
|
+
- gpt_helpr
|
34
|
+
- lmk
|
35
|
+
extensions: []
|
36
|
+
extra_rdoc_files: []
|
37
|
+
files:
|
38
|
+
- README.md
|
39
|
+
- bin/console
|
40
|
+
- bin/gpt_helpr
|
41
|
+
- bin/lmk
|
42
|
+
- bin/setup
|
43
|
+
- lib/gpt_helpr.rb
|
44
|
+
- lib/gpt_helpr/cli.rb
|
45
|
+
- lib/gpt_helpr/version.rb
|
46
|
+
homepage: https://etozzato.com
|
47
|
+
licenses:
|
48
|
+
- MIT
|
49
|
+
metadata:
|
50
|
+
homepage_uri: https://etozzato.com
|
51
|
+
source_code_uri: https://github.com/etozzato/gpt-helpr
|
52
|
+
changelog_uri: https://github.com/etozzato/gpt-helpr/blob/main/CHANGELOG.md
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.0.0
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubygems_version: 3.5.14
|
69
|
+
signing_key:
|
70
|
+
specification_version: 4
|
71
|
+
summary: GPT-Helpr is designed to save time and effort when sharing code snippets
|
72
|
+
test_files: []
|