clippy 0.1.pre → 0.1.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.
Files changed (5) hide show
  1. data/bin/clippy +38 -0
  2. data/lib/clippy.rb +138 -4
  3. data/rakefile.rb +19 -0
  4. data/readme.txt +41 -3
  5. metadata +56 -9
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+ require 'clippy'
4
+
5
+ ##
6
+ # Opts.
7
+ do_return = nil
8
+ did_cmd = nil
9
+ OptionParser.new do |opts|
10
+ opts.banner = "Clippy v#{Clippy.version} by Envygeeks"
11
+ opts.on('--paste', 'Paste') { do_return = Clippy.paste }
12
+ opts.on('--help', 'This') { do_return = opts }
13
+ opts.on('--clear', 'Clear') { did_cmd = Clippy.clear }
14
+
15
+ opts.on('--copy', 'Copy') do
16
+ unless ARGV.count > 0
17
+ text = ARGF.readlines.join.gsub(/\n$/, '')
18
+ else
19
+ if ARGV.count > 1
20
+ raise(RuntimeError, 'More than one arg.', 'Clippy')
21
+ else
22
+ text = ARGV.first
23
+ end
24
+ end
25
+
26
+ did_cmd = Clippy.copy(text)
27
+ end
28
+
29
+ opts.on('--version', 'version') { do_return = Clippy.version }
30
+ end.parse!
31
+
32
+ if do_return.nil? and did_cmd.nil?
33
+ system("#{File.expand_path(__FILE__)} --help")
34
+ else
35
+ if do_return
36
+ $stdout.puts do_return
37
+ end
38
+ end
@@ -1,8 +1,142 @@
1
+ require 'rbconfig'
2
+ require 'open3'
3
+
4
+ if RbConfig::CONFIG['host_os'] =~ /mswin/
5
+ require 'Win32API'
6
+ end
7
+
1
8
  class Clippy
9
+ private_class_method :new
10
+
11
+ ['UnsupportedOS', 'UnknownClipboard', 'InvalidEncoding'].each do |klass|
12
+ class_eval <<-CLASS
13
+ class #{klass} < StandardError
14
+ self
15
+ end
16
+ CLASS
17
+ end
18
+
19
+ class << self
20
+
21
+ ##
22
+ # Version.
23
+ def version
24
+ '0.1.1'
25
+ end
26
+
27
+ def binary_exist?(bin)
28
+ system("which #{bin} > /dev/null 2>&1")
29
+ end
30
+
31
+ ##
32
+ # Copy
33
+ def copy(data)
34
+ if RbConfig::CONFIG['host_os'] =~ /mswin/
35
+ if system('clip /? 2>&1 1>&0')
36
+ begin
37
+ tmpfile = Tempfile.new('clippy')
38
+ tmpfile.write(data)
39
+ tmpfile.flush
40
+ system("clip < #{tmpfile.path}")
41
+ ensure
42
+ tmpfile.close(true)
43
+ end
44
+ else
45
+ raise(UnsupportedOS, 'Your Windows version is too old.')
46
+ end
47
+ else
48
+ case true
49
+ when binary_exist?('xsel')
50
+ ['-p', '-b', '-s'].each do |opt|
51
+ Open3.popen3("xsel -i #{opt}") do |stdin|
52
+ stdin << data
53
+ end
54
+ end
55
+ when binary_exist?('pbcopy')
56
+ Open3.popen3('pbcopy') do |stdin|
57
+ stdin << data
58
+ end
59
+ when binary_exist?('xclip')
60
+ ['primary', 'secondary', 'clipboard'].each do |opt|
61
+ Open3.popen3("xclip -i -selection #{opt}") do |stdin|
62
+ stdin << data
63
+ end
64
+ end
65
+ else
66
+ raise(UnknownClipboard, 'Could not find a clipboard util.')
67
+ end
68
+ end
69
+
70
+ ((data.nil? or data.empty?)?(false):(data))
71
+ end
72
+
73
+ ##
74
+ # Paste
75
+ def paste(encoding = nil, which = nil)
76
+ if defined? Encoding and encoding
77
+ unless Encoding.list.map(&:to_s).include?(encoding)
78
+ raise(InvalidEncoding, 'The encoding you selected is unsupported')
79
+ end
80
+ end
81
+
82
+ if RbConfig::CONFIG['host_os'] =~ /mswin/
83
+ Win32API.new('user32', 'OpenClipboard', 'L', 'I').call(0)
84
+ data = Win32API.new('user32', 'GetClipboardData', 'I', 'P').call(1) || ''
85
+ Win32API.new('user32', 'CloseClipboard', [], 'I').call
86
+ else
87
+ case true
88
+ when binary_exist?('xsel')
89
+ cmd = 'xsel -o'
90
+
91
+ case which
92
+ when 'clipboard' then cmd+= ' -b'
93
+ when 'primary' then cmd+= ' -p'
94
+ when 'secondary' then cmd+= ' -s'
95
+ end
96
+
97
+ Open3.popen3(cmd) do |_, stdout|
98
+ data = stdout.read
99
+ end
100
+ when binary_exist?('pbpaste')
101
+ Open3.popen('pbpaste') do |_, stdout|
102
+ data = stdout.read || ''
103
+ end
104
+ when binary_exist?('xclip')
105
+ cmd = 'xclip -o'
106
+
107
+ case which
108
+ when 'clipboard' then cmd+= ' clipboard'
109
+ when 'primary' then cmd+= ' primary'
110
+ when 'secondary' then cmd+= ' secondary'
111
+ end
112
+
113
+ Open3.popen3(cmd) do |_, stdout|
114
+ data = stdout.read || ''
115
+ end
116
+ end
117
+ end
118
+
119
+ if defined? Encoding
120
+ if data.encoding.name != Encoding.default_external
121
+ data.encode(encoding ? encoding : Encoding.default_external)
122
+ end
123
+ end
124
+
125
+ ((data.nil? or data.empty?)?(false):(data))
126
+ end
127
+
128
+ def clear
129
+ if RbConfig::CONFIG['host_os'] =~ /mswin/
130
+ Win32API.new('user32', 'OpenClipboard', 'L', 'I').call(0)
131
+ Win32API.new('user32', 'EmptyClipboard', [], 'I').call
132
+ Win32API.new('user32', 'CloseClipboard', [], 'I').call
133
+ else
134
+ if copy('')
135
+ return true
136
+ end
137
+ end
2
138
 
3
- ##
4
- # Version.
5
- def self.version
6
- '0.1.pre'
139
+ false
140
+ end
7
141
  end
8
142
  end
@@ -0,0 +1,19 @@
1
+ require 'rubygems/package_task'
2
+ require 'rake/testtask'
3
+
4
+ task :default => [:test]
5
+
6
+ Rake::TestTask.new do |tfile|
7
+ tfile.verbose = true
8
+ tfile.pattern = "tests/**/*.rb"
9
+ end
10
+
11
+ if ARGV.include?('features')
12
+ require 'cucumber'
13
+ require 'cucumber/rake/task'
14
+ Cucumber::Rake::Task.new(:features)
15
+ end
16
+
17
+ Gem::PackageTask.new(eval(IO.read('clippy.gemspec'))) do |pkg|
18
+ pkg.need_tar, pkg.need_zip = true
19
+ end
data/readme.txt CHANGED
@@ -1,3 +1,41 @@
1
- Clippy is a clipboard alternative that takes a aim on simple code, the Windows
2
- side of clippy requires Ruby 1.9.2+ (well technically you could use Ruby 1.9.1)
3
- because it requires Encoding, FFI and Win32API to access user32.
1
+ ---
2
+ About:
3
+ Clippy is a cross-platform clipboard utility and script for Ruby.
4
+
5
+ ---
6
+ Requirements:
7
+ Windows:
8
+ Ruby1.9
9
+ Windows Vista+
10
+
11
+ Development:
12
+ cucumber
13
+ rake
14
+ rspec
15
+ minitest
16
+
17
+ All other distros should work with 1.8+
18
+
19
+ ---
20
+ Usage:
21
+ Shell:
22
+ clippy --copy '#1'
23
+ echo '#2' |clippy --copy
24
+ clipy --copy < 'file#3.txt'
25
+ Ruby:
26
+ require 'clippy'
27
+ Clippy.copy('#1')
28
+ Clippy.[paste, clear]
29
+
30
+ ---
31
+ Clippy v0.1 by Envygeeks
32
+ --paste Paste
33
+ --help This
34
+ --clear Clear
35
+ --copy Copy
36
+ --version Version
37
+
38
+ ---
39
+ I want to throw a big thank you to Nathaniel (@firestar) who took the time to
40
+ also build a Java version of clippy which will soon also be included as a
41
+ fallback for Windows XP users.
metadata CHANGED
@@ -1,28 +1,76 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clippy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.pre
5
- prerelease: 4
4
+ version: 0.1.1
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jordon Bedwell
9
+ - Nathaniel Davidson
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2011-12-25 00:00:00.000000000 Z
13
- dependencies: []
13
+ date: 2011-12-26 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ requirement: &16945060 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: *16945060
26
+ - !ruby/object:Gem::Dependency
27
+ name: rake
28
+ requirement: &16944420 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *16944420
37
+ - !ruby/object:Gem::Dependency
38
+ name: minitest
39
+ requirement: &16943860 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *16943860
48
+ - !ruby/object:Gem::Dependency
49
+ name: cucumber
50
+ requirement: &16943020 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *16943020
14
59
  description: A utility to access the systems clipboard.
15
60
  email:
16
61
  - jordon@envygeeks.com
17
- executables: []
62
+ - nathaniel.davidson@gmail.com
63
+ executables:
64
+ - clippy
18
65
  extensions: []
19
66
  extra_rdoc_files: []
20
67
  files:
68
+ - lib/clippy.rb
69
+ - bin/clippy
21
70
  - readme.txt
22
71
  - license.txt
23
72
  - rakefile.rb
24
73
  - gemfile.rb
25
- - lib/clippy.rb
26
74
  homepage: https://github.com/envygeeks/clippy
27
75
  licenses:
28
76
  - MIT
@@ -39,9 +87,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
39
87
  required_rubygems_version: !ruby/object:Gem::Requirement
40
88
  none: false
41
89
  requirements:
42
- - - ! '>'
90
+ - - ! '>='
43
91
  - !ruby/object:Gem::Version
44
- version: 1.3.1
92
+ version: '0'
45
93
  requirements: []
46
94
  rubyforge_project:
47
95
  rubygems_version: 1.8.11
@@ -49,4 +97,3 @@ signing_key:
49
97
  specification_version: 3
50
98
  summary: A utility to access the systems clipboard.
51
99
  test_files: []
52
- has_rdoc: false