concat.rb 1.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 485adb531e5c3690a614f6b1fd085cfd8a32751529d3ac7a177e8b5956637636
4
+ data.tar.gz: 9f82a733ebb42cf6dcd07c09066b7913669760150523dd444314240cfae2c425
5
+ SHA512:
6
+ metadata.gz: 3918ba6ee4c884f3a4da90e4c923b6cc262c5808795aba030ae49c84bb193c2ef26a0d807f4218ef172553769376851df8f4e19c5d03e305eccaf3dacd29464e
7
+ data.tar.gz: ed3baec6e7fcfb05d99ba14c0f3baf1465d74983cb467b509f4027f66cf10795cb62fff6f5f0a34e56e06271e183068bc788c50c91419ae273e0625b04d8d421
@@ -0,0 +1,47 @@
1
+ name: Ruby Gem
2
+
3
+ on:
4
+ push:
5
+ branches: ["main"]
6
+ pull_request:
7
+ branches: ["main"]
8
+
9
+ jobs:
10
+ build:
11
+ name: Build + Publish
12
+ runs-on: ubuntu-latest
13
+ permissions:
14
+ contents: read
15
+ packages: write
16
+
17
+ steps:
18
+ - uses: actions/checkout@v4
19
+
20
+ - name: Set up Ruby
21
+ uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: "3.3"
24
+
25
+ - name: Build gem
26
+ run: gem build *.gemspec
27
+
28
+ - name: Publish to GPR
29
+ if: github.event_name == 'push'
30
+ run: |
31
+ mkdir -p $HOME/.gem
32
+ printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
33
+ chmod 0600 $HOME/.gem/credentials
34
+ gem push --key github --host https://rubygems.pkg.github.com/${OWNER} *.gem
35
+ env:
36
+ GEM_HOST_API_KEY: "Bearer ${{ secrets.GITHUB_TOKEN }}"
37
+ OWNER: ${{ github.repository_owner }}
38
+
39
+ - name: Publish to RubyGems
40
+ if: github.event_name == 'push'
41
+ run: |
42
+ mkdir -p $HOME/.gem
43
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
44
+ chmod 0600 $HOME/.gem/credentials
45
+ gem push *.gem
46
+ env:
47
+ GEM_HOST_API_KEY: "${{ secrets.RUBYGEMS_AUTH_TOKEN }}"
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec
6
+
7
+ group :development do
8
+ #gem "minitest", "~> 5.0"
9
+ #gem "rake", "~> 13.0"
10
+ #gem "rubocop", "~> 1.21"
11
+ #gem "yard", "~> 0.9"
12
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,55 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mirrorfile (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.3)
10
+ json (2.18.0)
11
+ language_server-protocol (3.17.0.5)
12
+ lint_roller (1.1.0)
13
+ minitest (5.27.0)
14
+ parallel (1.27.0)
15
+ parser (3.3.10.0)
16
+ ast (~> 2.4.1)
17
+ racc
18
+ prism (1.7.0)
19
+ racc (1.8.1)
20
+ rainbow (3.1.1)
21
+ rake (13.3.1)
22
+ regexp_parser (2.11.3)
23
+ rubocop (1.82.1)
24
+ json (~> 2.3)
25
+ language_server-protocol (~> 3.17.0.2)
26
+ lint_roller (~> 1.1.0)
27
+ parallel (~> 1.10)
28
+ parser (>= 3.3.0.2)
29
+ rainbow (>= 2.2.2, < 4.0)
30
+ regexp_parser (>= 2.9.3, < 3.0)
31
+ rubocop-ast (>= 1.48.0, < 2.0)
32
+ ruby-progressbar (~> 1.7)
33
+ unicode-display_width (>= 2.4.0, < 4.0)
34
+ rubocop-ast (1.49.0)
35
+ parser (>= 3.3.7.2)
36
+ prism (~> 1.7)
37
+ ruby-progressbar (1.13.0)
38
+ unicode-display_width (3.2.0)
39
+ unicode-emoji (~> 4.1)
40
+ unicode-emoji (4.2.0)
41
+ yard (0.9.38)
42
+
43
+ PLATFORMS
44
+ ruby
45
+ x86_64-linux
46
+
47
+ DEPENDENCIES
48
+ minitest (~> 5.0)
49
+ mirrorfile!
50
+ rake (~> 13.0)
51
+ rubocop (~> 1.21)
52
+ yard (~> 0.9)
53
+
54
+ BUNDLED WITH
55
+ 2.7.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Your Name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,99 @@
1
+ # concat.rb
2
+
3
+ Concatenate files from directories into a single output, with the ability to reverse the process.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ gem install concat.rb
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### concat
14
+
15
+ Recursively read files from directories and output their contents with file path comments.
16
+
17
+ ```bash
18
+ # Concatenate all files in a directory
19
+ concat src/
20
+
21
+ # Filter by file extensions
22
+ concat lib/ --extensions=rb,py
23
+
24
+ # Multiple directories
25
+ concat src/ lib/ --extensions=js,ts
26
+
27
+ # Save to a file
28
+ concat app/ --extensions=rb > backup.txt
29
+ ```
30
+
31
+ Example output:
32
+
33
+ ```
34
+ # File path: ./lib/concat.rb
35
+ # frozen_string_literal: true
36
+
37
+ require_relative "concat/version"
38
+
39
+ module Concat
40
+ end
41
+
42
+ # File path: ./lib/concat/version.rb
43
+ # frozen_string_literal: true
44
+
45
+ module Concat
46
+ VERSION = "1.0.0"
47
+ end
48
+ ```
49
+
50
+ ### deconcat
51
+
52
+ Restore files from concatenated output. Reads from stdin and writes files to their original paths.
53
+
54
+ ```bash
55
+ # Restore from a file
56
+ cat backup.txt | deconcat
57
+
58
+ # Pipe directly
59
+ concat lib/ --extensions=rb | deconcat
60
+ ```
61
+
62
+ ### Clipboard integration
63
+
64
+ Use [clip.rb](https://github.com/n-at-han-k/clip.rb) to copy concatenated output to your clipboard:
65
+
66
+ ```bash
67
+ # Copy to clipboard
68
+ concat lib/ --extensions=rb | clip
69
+
70
+ # Append to clipboard
71
+ concat src/ | clip --append
72
+
73
+ # Restore from clipboard
74
+ clip | deconcat
75
+ ```
76
+
77
+ ## Contributing
78
+
79
+ Bug reports and pull requests are welcome on GitHub.
80
+
81
+ ## Development
82
+
83
+ After checking out the repo:
84
+
85
+ ```bash
86
+ bin/setup
87
+ bundle exec rake test
88
+ ```
89
+
90
+ Generate documentation:
91
+
92
+ ```bash
93
+ bundle exec yard doc
94
+ bundle exec yard server # Browse at http://localhost:8808
95
+ ```
96
+
97
+ ## License
98
+
99
+ The gem is available as open source under the terms of the [MIT License](LICENSE.txt).
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ #require "bundler/gem_tasks"
4
+ #require "rake/testtask"
5
+ #require "yard"
6
+ #
7
+ #Rake::TestTask.new(:test) do |t|
8
+ # t.libs << "test"
9
+ # t.libs << "lib"
10
+ # t.test_files = FileList["test/**/*_test.rb"]
11
+ #end
12
+ #
13
+ #YARD::Rake::YardocTask.new do |t|
14
+ # t.files = ["lib/**/*.rb"]
15
+ # t.options = ["--markup", "markdown"]
16
+ #end
17
+ #
18
+ #task default: :test
data/bin/console ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "concat"
6
+ require "irb"
7
+
8
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
data/concat.gemspec ADDED
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/concat/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "concat.rb"
7
+ spec.version = Concat::VERSION
8
+ spec.authors = ["Nathan Kidd"]
9
+ spec.email = ["nathankidd@hey.com"]
10
+
11
+ spec.summary = "Concatenate files from directories with optional extension filtering"
12
+
13
+ spec.description = <<~DESC
14
+ A simple CLI tool that recursively reads files from directories and outputs
15
+ their contents with file path comments. Supports filtering by file extensions.
16
+ DESC
17
+
18
+ spec.homepage = "https://github.com/n-at-han-k/concat.rb"
19
+ spec.license = "MIT"
20
+ spec.required_ruby_version = ">= 3.2.0"
21
+
22
+ spec.metadata["homepage_uri"] = spec.homepage
23
+ spec.metadata["source_code_uri"] = spec.homepage
24
+ spec.metadata["documentation_uri"] = spec.homepage
25
+ spec.metadata["rubygems_mfa_required"] = "true"
26
+
27
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|data)/}) }
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "minitest", "~> 5.0"
33
+ spec.add_development_dependency "rake", "~> 13.0"
34
+ spec.add_development_dependency "rubocop", "~> 1.21"
35
+ spec.add_development_dependency "yard", "~> 0.9"
36
+ end
data/exe/concat ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../lib/concat"
5
+
6
+ exit Concat::CLI.new.call(ARGV)
data/exe/deconcat ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../lib/concat"
5
+
6
+ exit Concat::DeconcatCLI.new.call(ARGV)
data/lib/concat/cli.rb ADDED
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "optparse"
4
+
5
+ module Concat
6
+ class CLI
7
+ COMMENT = "#"
8
+
9
+ def call(argv)
10
+ extensions = ""
11
+
12
+ parser = OptionParser.new do |parse|
13
+ parse.banner = "Usage: concat FOLDERS... --extensions=rb,py,md"
14
+ parse.on("--extensions=LIST", String, "File extensions to include") do |value|
15
+ extensions = ".{#{value}}"
16
+ end
17
+ end
18
+
19
+ parser.parse!(argv)
20
+
21
+ if argv.empty?
22
+ puts "ERROR!!!"
23
+ puts "You need to pass in a file path."
24
+ return 1
25
+ end
26
+
27
+ argv.each do |folder|
28
+ Dir.glob("#{folder}/**/*#{extensions}").each do |path|
29
+ if File.file?(path)
30
+ puts "#{COMMENT} File path: #{path}"
31
+ puts File.read(path)
32
+ puts
33
+ end
34
+ end
35
+ end
36
+
37
+ 0
38
+ end
39
+ end
40
+ end
41
+
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+
5
+ module Concat
6
+ class DeconcatCLI
7
+ def call(argv)
8
+ current_path = nil
9
+ content = []
10
+
11
+ ARGF.each_line do |line|
12
+ if line.start_with?("# File path: ")
13
+ File.write(current_path, content.join) if current_path && !content.empty?
14
+ current_path = line.sub("# File path: ", "").strip
15
+ content = []
16
+ FileUtils.mkdir_p(File.dirname(current_path))
17
+ else
18
+ content << line
19
+ end
20
+ end
21
+
22
+ File.write(current_path, content.join) if current_path && !content.empty?
23
+
24
+ 0
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Concat
4
+ VERSION = "1.0.1"
5
+ end
6
+
data/lib/concat.rb ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "concat/version"
4
+ require_relative "concat/cli"
5
+ require_relative "concat/deconcat_cli"
6
+
7
+ module Concat
8
+ end
9
+
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: concat.rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nathan Kidd
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2026-01-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.21'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.21'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.9'
69
+ description: |
70
+ A simple CLI tool that recursively reads files from directories and outputs
71
+ their contents with file path comments. Supports filtering by file extensions.
72
+ email:
73
+ - nathankidd@hey.com
74
+ executables:
75
+ - concat
76
+ - deconcat
77
+ extensions: []
78
+ extra_rdoc_files: []
79
+ files:
80
+ - ".github/workflows/gem-push.yml"
81
+ - Gemfile
82
+ - Gemfile.lock
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/setup
88
+ - concat.gemspec
89
+ - exe/concat
90
+ - exe/deconcat
91
+ - lib/concat.rb
92
+ - lib/concat/cli.rb
93
+ - lib/concat/deconcat_cli.rb
94
+ - lib/concat/version.rb
95
+ homepage: https://github.com/n-at-han-k/concat.rb
96
+ licenses:
97
+ - MIT
98
+ metadata:
99
+ homepage_uri: https://github.com/n-at-han-k/concat.rb
100
+ source_code_uri: https://github.com/n-at-han-k/concat.rb
101
+ documentation_uri: https://github.com/n-at-han-k/concat.rb
102
+ rubygems_mfa_required: 'true'
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: 3.2.0
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubygems_version: 3.5.22
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Concatenate files from directories with optional extension filtering
122
+ test_files: []