clip.rb 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3d5340ba053836445208d41b43f01a64089e220eeb2a657e17cc0ff160f5669c
4
+ data.tar.gz: 268a7efbaf151ed8de7d7eefcc6baff088fd7a2be191f78b20018f125d49d590
5
+ SHA512:
6
+ metadata.gz: c05ac3e5a4ba50ba4a3d610ec695fad7ef9811deaeacdd9b97bc614a9a9e87f32e373cfb4b864a6ee60d8460169bd70cdb398548c208c1dac8fe82dd606a98cd
7
+ data.tar.gz: cb647b96704b3943a51c232d1bd7fffada219fa2d3cc935d058820781d2aa8d06407c2de4e94ef21a6375a9e9e6594797e384f16d96e95120d84f064e5ede3e2
@@ -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,67 @@
1
+ # clip
2
+
3
+ A simple clipboard utility for piping content to xclip.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ gem install clip.rb
9
+ ```
10
+
11
+ Requires `xclip` to be installed on your system.
12
+
13
+ ## Usage
14
+
15
+ ```bash
16
+ # Copy file contents to clipboard
17
+ cat file.txt | clip
18
+
19
+ # Copy and echo the content
20
+ cat file.txt | clip -e
21
+
22
+ # Copy only the first N lines
23
+ cat file.txt | clip -l 10
24
+
25
+ # Wrap content in markdown code fence
26
+ cat script.rb | clip -m ruby
27
+
28
+ # Append to existing clipboard content
29
+ cat more.txt | clip -a
30
+
31
+ # Paste clipboard contents to stdout
32
+ clip
33
+
34
+ # Grep outputs filename AND content:
35
+ grep -rn "TODO" src/
36
+ # src/app.rb:42:# TODO: refactor this
37
+ # src/app.rb:87:# TODO: add tests
38
+ # src/lib.rb:12:# TODO: fix bug
39
+
40
+ # Use -l 1 to copy just the first match (with filename)
41
+ grep -rn "TODO" src/ | clip -l 1
42
+ ```
43
+
44
+ ### Options
45
+
46
+ - `-l`, `--line NUMBER` - Copy only the first N lines
47
+ - `-e`, `--echo` - Output copied content to stdout
48
+ - `-a`, `--append` - Append to clipboard instead of replacing
49
+ - `-m`, `--markdown [LANGUAGE]` - Wrap in markdown code fence
50
+ - `-h`, `--help` - Print help
51
+
52
+ ## Contributing
53
+
54
+ Bug reports and pull requests are welcome on GitHub.
55
+
56
+ ## Development
57
+
58
+ After checking out the repo:
59
+
60
+ ```bash
61
+ bin/setup
62
+ bundle exec rake test
63
+ ```
64
+
65
+ ## License
66
+
67
+ 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 "clip"
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/clip.gemspec ADDED
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/clip/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "clip.rb"
7
+ spec.version = Clip::VERSION
8
+ spec.authors = ["Nathan Kidd"]
9
+ spec.email = ["nathankidd@hey.com"]
10
+
11
+ spec.summary = "A simple clipboard utility for piping content to xclip"
12
+
13
+ spec.description = <<~DESC
14
+ A command-line tool for copying piped input to the clipboard with options
15
+ for line limits, markdown wrapping, appending, and echoing output.
16
+ DESC
17
+
18
+ spec.homepage = "https://github.com/n-at-han-k/clip"
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/clip ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../lib/clip"
5
+
6
+ exit Clip::CLI.new.call(ARGV)
data/lib/clip/cli.rb ADDED
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "optparse"
4
+
5
+ module Clip
6
+ module Clipboard
7
+ extend self
8
+
9
+ def <<(text)
10
+ IO.popen("xclip -selection clipboard", "w") { |clip| clip.print text }
11
+ end
12
+
13
+ def paste
14
+ `xclip -selection clipboard -o`
15
+ end
16
+ end
17
+
18
+ class CLI
19
+ def call(argv)
20
+ options = { line_number: false, echo: false, markdown: false, append: false }
21
+
22
+ OptionParser.new do |opts|
23
+ opts.banner = "Usage: cat file | clip [options]"
24
+
25
+ opts.on("-l", "--line NUMBER", Integer, "Line number to copy (default: all)") do |n|
26
+ options[:line_number] = n
27
+ end
28
+
29
+ opts.on("-e", "--echo", "After copying, output the copied contents to stdout") do
30
+ options[:echo] = true
31
+ end
32
+
33
+ opts.on("-a", "--append", "Append to clipboard instead of replacing") do
34
+ options[:append] = true
35
+ end
36
+
37
+ opts.on("-m", "--markdown [LANGUAGE]", "Wrap in markdown code fence") do |lang|
38
+ options[:markdown] = lang || ""
39
+ end
40
+
41
+ opts.on("-h", "--help", "Prints this help") do
42
+ puts opts
43
+ return 0
44
+ end
45
+ end.parse!(argv)
46
+
47
+ if $stdin.tty?
48
+ puts Clipboard.paste
49
+ else
50
+ output = $stdin.read
51
+
52
+ if options[:line_number] && options[:line_number] > 0
53
+ output = output.lines.first(options[:line_number]).join
54
+ end
55
+
56
+ if options[:markdown]
57
+ output = "```#{options[:markdown]}\n#{output}\n```"
58
+ end
59
+
60
+ if options[:append]
61
+ output = Clipboard.paste + output
62
+ end
63
+
64
+ Clipboard << output
65
+
66
+ options[:echo] ? puts(output) : puts("Copied! #{output.lines.count} lines")
67
+ end
68
+
69
+ 0
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Clip
4
+ VERSION = "1.0.0"
5
+ end
data/lib/clip.rb ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "clip/version"
4
+ require_relative "clip/cli"
5
+
6
+ module Clip
7
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: clip.rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
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 command-line tool for copying piped input to the clipboard with options
71
+ for line limits, markdown wrapping, appending, and echoing output.
72
+ email:
73
+ - nathankidd@hey.com
74
+ executables:
75
+ - clip
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - ".github/workflows/gem-push.yml"
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - clip.gemspec
88
+ - exe/clip
89
+ - lib/clip.rb
90
+ - lib/clip/cli.rb
91
+ - lib/clip/version.rb
92
+ homepage: https://github.com/n-at-han-k/clip
93
+ licenses:
94
+ - MIT
95
+ metadata:
96
+ homepage_uri: https://github.com/n-at-han-k/clip
97
+ source_code_uri: https://github.com/n-at-han-k/clip
98
+ documentation_uri: https://github.com/n-at-han-k/clip
99
+ rubygems_mfa_required: 'true'
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: 3.2.0
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubygems_version: 3.5.22
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: A simple clipboard utility for piping content to xclip
119
+ test_files: []