pry-clipboard2 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: 6d9f6045a596764c33b0636c0dc56404f5b5ce46d9b671506144288d9a245271
4
+ data.tar.gz: f8cb7abadba8fd8e18f76f41f82e5a9e9141e7d4b858cf7e1e4a1fb7008ad7a4
5
+ SHA512:
6
+ metadata.gz: 196aaa828597a87d6f390934f8d6ff9f74ee974fcba8c7251821599bca7a5dd0675beb63cdf947f1adf958476695d48dba0986c15cc3324a274a250950d0c8ca
7
+ data.tar.gz: bf68cf224e1007d19c04abaa7bf9e12d93c0fef236a9433219e65fd99a062357be7569db097cdb30cecca516fe88a99101d889beb28f908265d4a6edda2eaa60
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .ruby-gemset
19
+ .ruby-version
data/.rubocop.yml ADDED
@@ -0,0 +1,110 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ SuggestExtensions: false
4
+
5
+ Layout/ParameterAlignment:
6
+ EnforcedStyle: with_fixed_indentation
7
+ Layout/CaseIndentation:
8
+ EnforcedStyle: end
9
+ IndentOneStep: true
10
+ IndentationWidth: 2
11
+ Layout/DotPosition:
12
+ EnforcedStyle: trailing
13
+ Layout/ElseAlignment:
14
+ Enabled: false
15
+ Layout/EmptyLineAfterGuardClause:
16
+ Enabled: false
17
+ Layout/EndAlignment:
18
+ Enabled: false
19
+ Layout/MultilineMethodCallIndentation:
20
+ EnforcedStyle: indented
21
+ Layout/MultilineOperationIndentation:
22
+ EnforcedStyle: indented
23
+ Layout/SpaceAroundEqualsInParameterDefault:
24
+ EnforcedStyle: no_space
25
+ Layout/SpaceInsideHashLiteralBraces:
26
+ EnforcedStyle: no_space
27
+
28
+ # https://rubocop.readthedocs.io/en/latest/cops_metrics/#metrics
29
+ Metrics/AbcSize:
30
+ Enabled: false
31
+ Metrics/BlockLength:
32
+ Enabled: false
33
+ Metrics/ClassLength:
34
+ Enabled: false
35
+ Metrics/CyclomaticComplexity:
36
+ Enabled: false
37
+ Layout/LineLength:
38
+ Max: 120
39
+ # Allow comments to be long
40
+ IgnoredPatterns: ['\A#']
41
+ Metrics/MethodLength:
42
+ Enabled: false
43
+ Metrics/ModuleLength:
44
+ Enabled: false
45
+ Metrics/ParameterLists:
46
+ CountKeywordArgs: false
47
+ Metrics/PerceivedComplexity:
48
+ Enabled: false
49
+
50
+ Lint/BinaryOperatorWithIdenticalOperands:
51
+ Enabled: false
52
+ Lint/ConstantDefinitionInBlock:
53
+ Exclude:
54
+ - 'spec/**/*'
55
+ Lint/EmptyBlock:
56
+ Enabled: false
57
+ Lint/UselessAssignment:
58
+ Exclude:
59
+ - 'spec/**/*'
60
+ - 'webdriver/**/*'
61
+
62
+ # https://rubocop.readthedocs.io/en/latest/cops_naming/
63
+ Naming/AccessorMethodName:
64
+ Enabled: false
65
+ Naming/FileName:
66
+ Exclude:
67
+ - 'lib/pry-clipboard.rb'
68
+ Naming/PredicateName:
69
+ Exclude:
70
+ - 'spec/**/*'
71
+ Naming/MethodParameterName:
72
+ Enabled: false
73
+
74
+ # https://rubocop.readthedocs.io/en/latest/cops_style/
75
+ Style/AccessModifierDeclarations:
76
+ EnforcedStyle: inline
77
+ Style/AndOr:
78
+ EnforcedStyle: conditionals
79
+ Style/CaseEquality:
80
+ Enabled: false
81
+ Style/ClassAndModuleChildren:
82
+ EnforcedStyle: compact
83
+ Style/FormatStringToken:
84
+ Enabled: false
85
+ Style/Documentation:
86
+ Enabled: false
87
+ Style/FormatString:
88
+ EnforcedStyle: percent
89
+ Style/NumericPredicate:
90
+ IgnoredMethods: ['where']
91
+ Style/RedundantReturn:
92
+ Enabled: false
93
+ Style/RedundantSelf:
94
+ Enabled: false
95
+ Style/StringConcatenation:
96
+ Enabled: false
97
+ Style/StringLiterals:
98
+ EnforcedStyle: double_quotes
99
+ Style/SymbolArray:
100
+ EnforcedStyle: brackets
101
+ Style/TrailingCommaInArguments:
102
+ EnforcedStyleForMultiline: consistent_comma
103
+ Style/TrailingCommaInArrayLiteral:
104
+ EnforcedStyleForMultiline: consistent_comma
105
+ Style/TrailingCommaInHashLiteral:
106
+ EnforcedStyleForMultiline: consistent_comma
107
+ Style/TrailingUnderscoreVariable:
108
+ Enabled: false
109
+ Style/WordArray:
110
+ EnforcedStyle: brackets
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in pry-clipboard.gemspec
6
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Yuichi Tateno, 2022 Rob Galanakis
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Makefile ADDED
@@ -0,0 +1,16 @@
1
+ install:
2
+ bundle install
3
+ cop:
4
+ bundle exec rubocop
5
+ fix:
6
+ bundle exec rubocop --auto-correct-all
7
+ fmt: fix
8
+
9
+ test:
10
+ RACK_ENV=test bundle exec rspec spec/
11
+ testf:
12
+ RACK_ENV=test bundle exec rspec spec/ --fail-fast --seed=1
13
+
14
+ build:
15
+ gem build pry-clipboard2.gemspec
16
+ gem push pry-clipboard2-1.0.0.gem
data/README.md ADDED
@@ -0,0 +1,138 @@
1
+ # pry-clipboard
2
+
3
+ Pry clipboard utility.
4
+
5
+ Copy history/result to clipboard.
6
+
7
+ ## Installation
8
+
9
+ $ gem install pry-clipboard2
10
+
11
+ ## Recommend setting
12
+
13
+ Your ~/.pryrc
14
+
15
+ ```ruby
16
+ begin
17
+ require 'pry-clipboard2'
18
+ # aliases
19
+ Pry.config.commands.alias_command 'ch', 'copy-history'
20
+ Pry.config.commands.alias_command 'cr', 'copy-result'
21
+ rescue LoadError => e
22
+ warn "can't load pry-clipboard"
23
+ end
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ ```ruby
29
+ require 'pry-clipboard2'
30
+ copy-history --help
31
+ copy-result --help
32
+ paste --help
33
+ ```
34
+
35
+ ### Copy history to clipboard
36
+
37
+ ```ruby
38
+ pry(main)> def fib(n)
39
+ pry(main)* n < 2 ? n : fib(n-1) + fib(n-2)
40
+ pry(main)* end
41
+ > nil
42
+ pry(main)> fib(10)
43
+ => 55
44
+ pry(main)> copy-history
45
+ -*-*- Copy history to clipboard -*-*-
46
+ fib(10)
47
+ ```
48
+
49
+ ### Copy history to clipboard with result
50
+
51
+ ```ruby
52
+ [5] pry(main)> fib(10)
53
+ => 55
54
+ [6] pry(main)> copy-history -l
55
+ -*-*- Copy history to clipboard -*-*-
56
+ fib(10)
57
+ #=> 55
58
+ ```
59
+
60
+ ### Copy result
61
+
62
+ ```ruby
63
+ pry(main)> 'hello' * 3
64
+ => "hellohellohello"
65
+ pry(main)> copy-result
66
+ -*-*- Copy result to clipboard -*-*-
67
+ hellohellohello
68
+ ```
69
+
70
+ ### paste
71
+
72
+ ```ruby
73
+ pry(main)> Clipboard.copy '3 * 5'
74
+ => "3 * 5"
75
+ pry(main)> paste
76
+ => 15
77
+ ```
78
+
79
+ ### N / --head / --tail options
80
+
81
+ ```ruby
82
+ pry(main)> history --tail 10
83
+ 4: fib(10)
84
+ 5: copy-history
85
+ 6: copy-history -l
86
+ 7: fib(10)
87
+ 8: copy-history -l
88
+ 9: 'hello' * 3
89
+ 10: copy-result
90
+ 11: history --tail 10
91
+ 12: copy-result --tail 3
92
+ 13: copy-history --tail 3
93
+ pry(main)> copy-history 9
94
+ -*-*- Copy history to clipboard -*-*-
95
+ 'hello' * 3
96
+ pry(main)> copy-history -tail 5
97
+ -*-*- Copy history to clipboard -*-*-
98
+ copy-result
99
+ history --tail 10
100
+ copy-result --tail 3
101
+ copy-history --tail 3
102
+ history --tail 10
103
+ ```
104
+
105
+ ### --range option
106
+
107
+ ```ruby
108
+ pry(main)> history --head 10
109
+ 1: def fib(n)
110
+ 2: n < 2 ? n : fib(n-1) + fib(n-2)
111
+ 3: end
112
+ 4: fib(10)
113
+ 5: copy-history
114
+ 6: copy-history -l
115
+ 7: fib(10)
116
+ 8: copy-history -l
117
+ 9: 'hello' * 3
118
+ 10: copy-result
119
+ pry(main)> copy-history --range 1..4
120
+ -*-*- Copy history to clipboard -*-*-
121
+ def fib(n)
122
+ n < 2 ? n : fib(n-1) + fib(n-2)
123
+ end
124
+ fib(10)
125
+ ```
126
+
127
+ ### --grep option
128
+
129
+ ```ruby
130
+ pry(main)> copy-history --grep def
131
+ -*-*- Copy history to clipboard -*-*-
132
+ def fib(n)
133
+ def hello
134
+ ```
135
+
136
+ ## Author
137
+
138
+ * Rob Galanakis, based on work by Yuichi Tateno
@@ -0,0 +1,111 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pry"
4
+ require "clipboard"
5
+
6
+ # Originally from https://github.com/hotchpotch/pry-clipboard
7
+ # but modified since it is broken in Ruby 2.7
8
+ module Pry::Clipboard
9
+ Command = Pry::CommandSet.new do
10
+ create_command "paste" do
11
+ description "Paste from clipboard"
12
+
13
+ banner <<-BANNER
14
+ Usage: paste [-q|--quiet]
15
+ BANNER
16
+
17
+ def options(opt)
18
+ opt.on :q, :quiet, "quiet output", optional: true
19
+ end
20
+
21
+ def process
22
+ str = Clipboard.paste
23
+ unless opts.present?(:q)
24
+ pry_instance.output.puts green("-*-*- Paste from clipboard -*-*-")
25
+ pry_instance.output.puts str
26
+ end
27
+ eval_string << str
28
+ end
29
+ end
30
+
31
+ create_command "copy-history" do
32
+ description "Copy history to clipboard"
33
+
34
+ banner <<-BANNER
35
+ Usage: copy-history [N] [-T|--tail N] [-H|--head N] [-R|--range N..M] [-G|--grep match] [-l] [-q|--quiet]
36
+ e.g: `copy-history`
37
+ e.g: `copy-history -l`
38
+ e.g: `copy-history 10`
39
+ e.g: `copy-history -H 10`
40
+ e.g: `copy-history -T 5`
41
+ e.g: `copy-history -R 5..10`
42
+ BANNER
43
+
44
+ def options(opt)
45
+ opt.on :l, "Copy history with last result", optional: true
46
+ opt.on :H, :head, "Copy the first N items.", optional: true, as: Integer
47
+ opt.on :T, :tail, "Copy the last N items.", optional: true, as: Integer
48
+ opt.on :R, :range, "Copy the given range of lines.", optional: true, as: Range
49
+ opt.on :G, :grep, "Copy lines matching the given pattern.", optional: true, as: String
50
+ opt.on :q, :quiet, "quiet output", optional: true
51
+ end
52
+
53
+ def process
54
+ history = Pry::Code(Pry.history.to_a)
55
+
56
+ history = if num_arg
57
+ history.take_lines(num_arg, 1)
58
+ else
59
+ history = history.grep(opts[:grep]) if opts.present?(:grep)
60
+ if opts.present?(:range)
61
+ history.between(opts[:range])
62
+ elsif opts.present?(:head)
63
+ history.take_lines(1, opts[:head] || 10)
64
+ elsif opts.present?(:tail) || opts.present?(:grep)
65
+ n = opts[:tail] || 10
66
+ n = history.lines.count if n > history.lines.count
67
+ history.take_lines(-n, n)
68
+ else
69
+ history.take_lines(-1, 1)
70
+ end
71
+ end
72
+
73
+ str = history.raw
74
+ str += "#=> #{pry_instance.last_result}\n" if opts.present?(:l)
75
+ Clipboard.copy str
76
+
77
+ return if opts.present?(:q)
78
+ pry_instance.output.puts green("-*-*- Copy history to clipboard -*-*-")
79
+ pry_instance.output.puts str
80
+ end
81
+
82
+ def num_arg
83
+ first = args[0]
84
+ first.to_i if first && first.to_i.to_s == first
85
+ end
86
+ end
87
+
88
+ create_command "copy-result" do
89
+ description "Copy result to clipboard."
90
+
91
+ banner <<-BANNER
92
+ Usage: copy-result [-q|--quiet]
93
+ BANNER
94
+
95
+ def options(opt)
96
+ opt.on :q, :quiet, "quiet output", optional: true
97
+ end
98
+
99
+ def process
100
+ res = "#{pry_instance.last_result}\n"
101
+ Clipboard.copy res
102
+
103
+ return if opts.present?(:q)
104
+ pry_instance.output.puts green("-*-*- Copy result to clipboard -*-*-")
105
+ pry_instance.output.print res
106
+ end
107
+ end
108
+ end
109
+ end
110
+
111
+ Pry.commands.import Pry::Clipboard::Command
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PryClipboard
4
+ VERSION = "1.0.0"
5
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "English"
4
+
5
+ require File.expand_path("lib/pry-clipboard2/version", __dir__)
6
+
7
+ Gem::Specification.new do |gem|
8
+ gem.authors = ["Rob Galanakis"]
9
+ gem.description = "pry-clipboard2 allows you to copy Pry results and history to your clipboard."
10
+ gem.email = ["rob.galanakis@gmail.com"]
11
+ gem.summary = "pry clipboard utility"
12
+ gem.homepage = "https://github.com/lithictech/pry-clipboard"
13
+ gem.licenses = "MIT"
14
+ gem.files = `git ls-files`.split($OUTPUT_RECORD_SEPARATOR)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.metadata["rubygems_mfa_required"] = "true"
18
+ gem.name = "pry-clipboard2"
19
+ gem.platform = Gem::Platform::RUBY
20
+ gem.require_paths = ["lib"]
21
+ gem.required_ruby_version = ">= 2.7"
22
+ gem.version = PryClipboard::VERSION
23
+
24
+ gem.add_dependency "clipboard", "~> 1"
25
+ gem.add_dependency "pry", "~> 0"
26
+
27
+ gem.add_development_dependency("rubocop", "~> 1.11")
28
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pry-clipboard2
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Rob Galanakis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-03-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: clipboard
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '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.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.11'
55
+ description: pry-clipboard2 allows you to copy Pry results and history to your clipboard.
56
+ email:
57
+ - rob.galanakis@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rubocop.yml"
64
+ - Gemfile
65
+ - LICENSE
66
+ - Makefile
67
+ - README.md
68
+ - lib/pry-clipboard.rb
69
+ - lib/pry-clipboard2/version.rb
70
+ - pry-clipboard2.gemspec
71
+ homepage: https://github.com/lithictech/pry-clipboard
72
+ licenses:
73
+ - MIT
74
+ metadata:
75
+ rubygems_mfa_required: 'true'
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '2.7'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubygems_version: 3.1.6
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: pry clipboard utility
95
+ test_files: []