pry-clipboard 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
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
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+
6
+ script: bundle exec rake test
data/.watchr ADDED
@@ -0,0 +1,3 @@
1
+
2
+ watch( 'test/test_.*\.rb' ) {|md| system("bundle exec rake test") }
3
+ watch( 'lib/(.*)\.rb' ) {|md| system("bundle exec rake test") }
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pry-clipboard.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Yuichi Tateno
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.
@@ -0,0 +1,138 @@
1
+ # pry-clipboard
2
+
3
+ [![Build Status](https://secure.travis-ci.org/hotchpotch/pry-clipboard.png?branch=master)](http://travis-ci.org/hotchpotch/pry-clipboard)
4
+
5
+ Pry clipboard utility.
6
+
7
+ Copy history/result to clipboard.
8
+
9
+ ## Installation
10
+
11
+ $ gem install pry-clipboard
12
+
13
+ ## Recommend setting
14
+
15
+ Your ~/.pryrc
16
+
17
+ ```ruby
18
+ begin
19
+ require 'pry-clipboard'
20
+ # aliases
21
+ Pry.config.commands.alias_command 'ch', 'copy-history'
22
+ Pry.config.commands.alias_command 'cr', 'copy-result'
23
+ rescue LoadError => e
24
+ warn "can't load pry-clipboard"
25
+ end
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ ```ruby
31
+ require 'pry-clipboard'
32
+ copy-history --help
33
+ copy-result --help
34
+ paste --help
35
+ ```
36
+
37
+ ### Copy history to clipboard
38
+
39
+ ```ruby
40
+ pry(main)> def fib(n)
41
+ pry(main)* n < 2 ? n : fib(n-1) + fib(n-2)
42
+ pry(main)* end
43
+ > nil
44
+ pry(main)> fib(10)
45
+ => 55
46
+ pry(main)> copy-history
47
+ -*-*- Copy history to clipboard -*-*-
48
+ fib(10)
49
+ ```
50
+
51
+ ### Copy history to clipboard with result
52
+
53
+ ```ruby
54
+ [5] pry(main)> fib(10)
55
+ => 55
56
+ [6] pry(main)> copy-history -l
57
+ -*-*- Copy history to clipboard -*-*-
58
+ fib(10)
59
+ #=> 55
60
+ ```
61
+
62
+ ### Copy result
63
+
64
+ ```ruby
65
+ pry(main)> 'hello' * 3
66
+ => "hellohellohello"
67
+ pry(main)> copy-result
68
+ -*-*- Copy result to clipboard -*-*-
69
+ hellohellohello
70
+ ```
71
+
72
+ ### paste
73
+
74
+ ```ruby
75
+ pry(main)> Clipboard.copy '3 * 5'
76
+ => "3 * 5"
77
+ pry(main)> paste
78
+ => 15
79
+ ```
80
+
81
+ ### --head / --tail options
82
+
83
+ ```ruby
84
+ pry(main)> history --tail 10
85
+ 4: fib(10)
86
+ 5: copy-history
87
+ 6: copy-history -l
88
+ 7: fib(10)
89
+ 8: copy-history -l
90
+ 9: 'hello' * 3
91
+ 10: copy-result
92
+ 11: history --tail 10
93
+ 12: copy-result --tail 3
94
+ 13: copy-history --tail 3
95
+ pry(main)> copy-history -tail 5
96
+ -*-*- Copy history to clipboard -*-*-
97
+ copy-result
98
+ history --tail 10
99
+ copy-result --tail 3
100
+ copy-history --tail 3
101
+ history --tail 10
102
+ ```
103
+
104
+ ### --range option
105
+
106
+ ```ruby
107
+ pry(main)> history --head 10
108
+ 1: def fib(n)
109
+ 2: n < 2 ? n : fib(n-1) + fib(n-2)
110
+ 3: end
111
+ 4: fib(10)
112
+ 5: copy-history
113
+ 6: copy-history -l
114
+ 7: fib(10)
115
+ 8: copy-history -l
116
+ 9: 'hello' * 3
117
+ 10: copy-result
118
+ pry(main)> copy-history --range 1..4
119
+ -*-*- Copy history to clipboard -*-*-
120
+ def fib(n)
121
+ n < 2 ? n : fib(n-1) + fib(n-2)
122
+ end
123
+ fib(10)
124
+ ```
125
+
126
+ ### --grep option
127
+
128
+ ```ruby
129
+ pry(main)> copy-history --grep def
130
+ -*-*- Copy history to clipboard -*-*-
131
+ def fib(n)
132
+ def hello
133
+ ```
134
+
135
+ ## Author
136
+
137
+ * Yuichi Tateno
138
+
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ desc "Set up and run tests"
5
+ task :default => [:test]
6
+
7
+ desc "Run tests"
8
+ task :test do
9
+ sh "bacon -Itest -rubygems -a -q"
10
+ end
@@ -0,0 +1,103 @@
1
+
2
+ require 'pry'
3
+ require 'clipboard'
4
+ require "pry-clipboard/version"
5
+
6
+ module PryClipboard
7
+ Command = Pry::CommandSet.new do
8
+ create_command "paste" do
9
+ description "Paste from clipboard"
10
+
11
+ banner <<-BANNER
12
+ Usage: paste [-q|--quiet]
13
+ BANNER
14
+
15
+ def options(opt)
16
+ opt.on :q, :quiet, "quiet output", :optional => true
17
+ end
18
+
19
+ def process
20
+ str = Clipboard.paste
21
+ unless opts.present?(:q)
22
+ _pry_.output.puts text.green("-*-*- Paste from clipboard -*-*-")
23
+ _pry_.output.puts str
24
+ end
25
+ eval_string << str
26
+ end
27
+ end
28
+
29
+ create_command "copy-history" do
30
+ description "Copy history to clipboard"
31
+
32
+ banner <<-BANNER
33
+ Usage: copy-history [-r] [-q|--quiet]
34
+
35
+ e.g: `copy-history`
36
+ e.g: `copy-history -l`
37
+ e.g: `copy-history -H 10`
38
+ e.g: `copy-history -T 5`
39
+ e.g: `copy-history -R 5..10`
40
+ BANNER
41
+
42
+ def options(opt)
43
+ opt.on :l, "Copy history with last result", :optional => true
44
+ opt.on :H, :head, "Copy the first N items.", :optional => true, :as => Integer
45
+ opt.on :T, :tail, "Copy the last N items.", :optional => true, :as => Integer
46
+ opt.on :R, :range, "Copy the given range of lines.", :optional => true, :as => Range
47
+ opt.on :G, :grep, "Copy lines matching the given pattern.", :optional => true, :as => String
48
+ opt.on :q, :quiet, "quiet output", :optional => true
49
+ end
50
+
51
+ def process
52
+ history = Pry::Code(Pry.history.to_a)
53
+ history = history.grep(opts[:grep]) if opts.present?(:grep)
54
+ history = case
55
+ when opts.present?(:range)
56
+ history.between(opts[:range])
57
+ when opts.present?(:head)
58
+ history.take_lines(1, opts[:head] || 10)
59
+ when opts.present?(:tail) || opts.present?(:grep)
60
+ n = opts[:tail] || 10
61
+ n = history.lines.count if n > history.lines.count
62
+ history.take_lines(-n, n)
63
+ else
64
+ history.take_lines(-1, 1)
65
+ end
66
+
67
+ str = history.raw
68
+ str += "#=> #{_pry_.last_result}\n" if opts.present?(:l)
69
+ Clipboard.copy str
70
+
71
+ unless opts.present?(:q)
72
+ _pry_.output.puts text.green("-*-*- Copy history to clipboard -*-*-")
73
+ _pry_.output.puts str
74
+ end
75
+ end
76
+ end
77
+
78
+ create_command "copy-result" do
79
+ description "Copy result to clipboard."
80
+
81
+ banner <<-BANNER
82
+ Usage: copy-result [-q|--quiet]
83
+ BANNER
84
+
85
+ def options(opt)
86
+ opt.on :q, :quiet, "quiet output", :optional => true
87
+ end
88
+
89
+ def process
90
+ res = "#{_pry_.last_result}\n"
91
+ Clipboard.copy res
92
+
93
+ unless opts.present?(:q)
94
+ _pry_.output.puts text.green("-*-*- Copy result to clipboard -*-*-")
95
+ _pry_.output.print res
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
101
+
102
+ Pry.commands.import PryClipboard::Command
103
+
@@ -0,0 +1,3 @@
1
+ module PryClipboard
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/pry-clipboard/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Yuichi Tateno"]
6
+ gem.email = ["hotchpotch@gmail.com"]
7
+ gem.summary = gem.description = %q{pry clipboard utility}
8
+ gem.homepage = "https://github.com/hotchpotch/pry-clipboard"
9
+
10
+ gem.files = `git ls-files`.split($\)
11
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
12
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
13
+ gem.name = "pry-clipboard"
14
+ gem.require_paths = ["lib"]
15
+ gem.version = PryClipboard::VERSION
16
+
17
+ gem.add_dependency 'pry'
18
+ gem.add_dependency 'clipboard'
19
+
20
+ gem.add_development_dependency 'rr', '~> 1.0'
21
+ gem.add_development_dependency 'bacon', '~> 1.1'
22
+ gem.add_development_dependency 'open4', '~> 1.3'
23
+ gem.add_development_dependency 'rake'
24
+ end
@@ -0,0 +1,13 @@
1
+
2
+ $:.unshift File.expand_path '../../lib', __FILE__
3
+ require 'pry-clipboard'
4
+
5
+ def gempath(gemname)
6
+ Gem.loaded_specs.each do |key, spec|
7
+ if key == gemname
8
+ return Pathname.new(spec.full_gem_path)
9
+ end
10
+ end
11
+ end
12
+
13
+ require gempath('pry').join('test/helper.rb').to_s
@@ -0,0 +1,163 @@
1
+
2
+ require 'helper'
3
+ require 'rr'
4
+
5
+ describe PryClipboard::Command do
6
+ extend RR::Adapters::RRMethods
7
+
8
+ before do
9
+ Pry.history.clear
10
+ RR.reset
11
+ end
12
+
13
+ after do
14
+ RR.verify
15
+ end
16
+
17
+ it "#paste" do
18
+ mock(Clipboard).paste { '3 * 3' }
19
+ mock_pry(*%w(
20
+ paste
21
+ )).should =~ /Paste from clipboard.*\n3 \* 3\n=> 9/
22
+ end
23
+
24
+ it "#paste -q" do
25
+ mock(Clipboard).paste { '3 * 3' }
26
+ mock_pry(*%w(
27
+ paste\ -q
28
+ )).should.not =~ /Paste from clipboard/
29
+ end
30
+
31
+ it "#copy-history" do
32
+ mock(Clipboard).copy <<EOF
33
+ 'abc'
34
+ EOF
35
+ mock(Clipboard).copy <<EOF
36
+ "efg"
37
+ EOF
38
+
39
+ mock_pry(*%w(
40
+ 'abc'
41
+ copy-history
42
+ )).should =~ /clipboard.*\n'abc'\n/
43
+
44
+ mock_pry(*%w(
45
+ 'abc'
46
+ "efg"
47
+ copy-history
48
+ )).should =~ /clipboard.*\n"efg"\n/
49
+ end
50
+
51
+ it "#copy-history -l" do
52
+ mock(Clipboard).copy("10 * 10\n#=> 100\n")
53
+ mock_pry(*%w(
54
+ 10\ *\ 10
55
+ copy-history\ -l
56
+ )).should =~ /clipboard.*\n10 \* 10\n#=> 100\n/
57
+ end
58
+
59
+ it "#copy-history -q" do
60
+ mock(Clipboard).copy <<EOF
61
+ 'abc'
62
+ EOF
63
+ mock(Clipboard).copy <<EOF
64
+ "efg"
65
+ EOF
66
+
67
+ mock_pry(*%w(
68
+ 'abc'
69
+ copy-history\ -q
70
+ )).should.not =~ /clipboard.*\n'abc'\n/
71
+
72
+ mock_pry(*%w(
73
+ 'abc'
74
+ "efg"
75
+ copy-history\ -q
76
+ )).should.not =~ /clipboard.*\n"efg"\n/
77
+ end
78
+
79
+ it "#copy-history --head 3" do
80
+ mock(Clipboard).copy <<EOF
81
+ 1
82
+ 2
83
+ 3
84
+ EOF
85
+ mock_pry(*%w(
86
+ 1
87
+ 2
88
+ 3
89
+ 4
90
+ 5
91
+ copy-history\ --head\ 3
92
+ )).should =~ /clipboard/
93
+ end
94
+
95
+ it "#copy-history --tail 3" do
96
+ mock(Clipboard).copy <<EOF
97
+ 3
98
+ 4
99
+ 5
100
+ EOF
101
+ mock_pry(*%w(
102
+ 1
103
+ 2
104
+ 3
105
+ 4
106
+ 5
107
+ copy-history\ --tail\ 3
108
+ )).should =~ /clipboard/
109
+ end
110
+
111
+ it "#copy-history --range 2..4" do
112
+ mock(Clipboard).copy <<EOF
113
+ 2
114
+ 3
115
+ 4
116
+ EOF
117
+ mock_pry(*%w(
118
+ 1
119
+ 2
120
+ 3
121
+ 4
122
+ 5
123
+ copy-history\ --range\ 2..4
124
+ )).should =~ /clipboard/
125
+ end
126
+
127
+ it "#copy-history --grep foo" do
128
+ mock(Clipboard).copy <<EOF
129
+ 'foo'
130
+ 'foobar'
131
+ EOF
132
+ mock_pry(*%w(
133
+ 1
134
+ 'foo'
135
+ 'foobar'
136
+ 'baz'
137
+ copy-history\ --grep\ foo)
138
+ ).should =~ /clipboard/
139
+ end
140
+
141
+ it "#copy-history --range 1..2 --grep foo" do
142
+ mock(Clipboard).copy <<EOF
143
+ 'foo'
144
+ EOF
145
+ mock_pry(*%w(
146
+ 1
147
+ 'foo'
148
+ 'foobar'
149
+ 'baz'
150
+ copy-history\ --range\ 1..2\ --grep\ foo)
151
+ ).should =~ /clipboard/
152
+ end
153
+
154
+ it "#copy-result" do
155
+ mock(Clipboard).copy("1000\n")
156
+ mock_pry("10 * 10 * 10", "copy-result").should =~ /clipboard.*\n1000\n/
157
+ end
158
+
159
+ it "#copy-result -q" do
160
+ mock(Clipboard).copy("1000\n")
161
+ mock_pry("10 * 10 * 10", "copy-result -q").should.not =~ /clipboard.*\n1000\n/
162
+ end
163
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pry-clipboard
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Yuichi Tateno
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: pry
16
+ requirement: &2172295820 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2172295820
25
+ - !ruby/object:Gem::Dependency
26
+ name: clipboard
27
+ requirement: &2172295120 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2172295120
36
+ - !ruby/object:Gem::Dependency
37
+ name: rr
38
+ requirement: &2172294620 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '1.0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *2172294620
47
+ - !ruby/object:Gem::Dependency
48
+ name: bacon
49
+ requirement: &2172294080 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.1'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *2172294080
58
+ - !ruby/object:Gem::Dependency
59
+ name: open4
60
+ requirement: &2172293440 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: '1.3'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *2172293440
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: &2172292980 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *2172292980
80
+ description: pry clipboard utility
81
+ email:
82
+ - hotchpotch@gmail.com
83
+ executables: []
84
+ extensions: []
85
+ extra_rdoc_files: []
86
+ files:
87
+ - .gitignore
88
+ - .travis.yml
89
+ - .watchr
90
+ - Gemfile
91
+ - LICENSE
92
+ - README.md
93
+ - Rakefile
94
+ - lib/pry-clipboard.rb
95
+ - lib/pry-clipboard/version.rb
96
+ - pry-clipboard.gemspec
97
+ - test/helper.rb
98
+ - test/test_pry_clipboard.rb
99
+ homepage: https://github.com/hotchpotch/pry-clipboard
100
+ licenses: []
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 1.8.16
120
+ signing_key:
121
+ specification_version: 3
122
+ summary: pry clipboard utility
123
+ test_files:
124
+ - test/helper.rb
125
+ - test/test_pry_clipboard.rb