clippy 2.2.1 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a6b2df7a88254eb2a4e1f351633e964ce2edb332
4
- data.tar.gz: 5a75718708ae18f8c77123ff6f40f58bfb2df741
3
+ metadata.gz: c6f7e86513ddda4fedd2dabdfa424d290233c390
4
+ data.tar.gz: f127557e982d74e3377f7cfb114d81a21b178306
5
5
  SHA512:
6
- metadata.gz: 723329e7799009e93df6c1f5c1ce0c866b8103737bde04587821a6f66e8be3e2c138a7541e650a1b9a4bb9a511c64d5a9eaf4830e2420880c5bb377020a1e463
7
- data.tar.gz: 3b9a7bf578f6d029870f7840e7054fd3a955210c48edb5046cad68f8e0dd22cbe92404e5a2db2ed66d4f3238b2d0c6cbf33290757f3a8f43a8baeff2b404857f
6
+ metadata.gz: 605f99bab2aa4c37f4a9f80e6c361a4ffe874ca939b6721f20bd672411f8d619649a896d318a1322062ef75f59d186d1ce83ceada9d6271fd970fd16acd732d8
7
+ data.tar.gz: e6be611a0a543f328c9b8f184af1d23bd181788f6ec057a55db743659e62e5ce1b9009f24100a9165b7b5aa09500df5699fc4b0b49227915cfc1f28cfe3a1d31
data/Gemfile CHANGED
@@ -3,4 +3,5 @@ gemspec
3
3
 
4
4
  group :development do
5
5
  gem "rake"
6
+ gem "pry"
6
7
  end
data/README.md CHANGED
@@ -8,29 +8,26 @@ Clippy is a cross-platform clipboard utility and script for Ruby.
8
8
  * OS X: `pbcopy`
9
9
  * Linux: `xsel` || `xclip`
10
10
 
11
- *Right now there is a bug with jRuby stable that causes Clippy to fail, this bug is inside of Open3.popen3 where jRuby actually short-circuits and does not meet the same guidelines as Ruby1.9+, you can see the progress of this bug at: http://jira.codehaus.org/browse/JRUBY-6409 -- this has been fixed in jRuby-head so if you plan to use Clippy please use jRuby-head until a new stable is released.*
12
-
13
- ---
14
11
  Examples:
15
12
 
16
13
  ```bash
17
14
  clippy --copy '#1'
18
- clippy --paste
19
- echo '#2' |clippy --copy
20
15
  clippy --copy < 'file#3.txt'
16
+ echo '#2' |clippy --copy
17
+ clippy --paste
21
18
  ```
22
19
 
23
20
  ```ruby
24
21
  require 'clippy'
22
+ Clippy.paste; Clippy.clear
25
23
  Clippy.copy('#1')
26
- Clippy.paste and Clippy.clear
27
24
  ```
28
25
 
29
26
  ```
30
- Clippy v2.0.11: Clippy [--copy [< File] ['Text']]
31
- --paste Paste
32
- --help This
33
- --clear Clear
34
- --version Version
35
- --copy Copy a String or STDIN
27
+ Clippy v2.3.0: Clippy [--copy [< File] ['Text']]
28
+ -p, --paste Paste
29
+ -N, --no-unescape Do not unescape \n
30
+ -c, --copy [STR] Copy a String or STDIN```
31
+ -v, --version Version
32
+ -C, --clear Clear
36
33
  ```
data/bin/clippy CHANGED
@@ -6,13 +6,12 @@ require "optparse"
6
6
  OptionParser.new do |opts|
7
7
  opts.banner = "Clippy v#{Clippy::VERSION}: Clippy [--copy [< File] ['Text']]"
8
8
 
9
- opts.on("--paste", "Paste") { $stdout.puts Clippy.paste }
10
- opts.on("--help", "This") { $stdout.puts opts }
11
- opts.on("--clear", "Clear") { exit Clippy.clear ? 0 : 1 }
12
- opts.on("--version", "Version") { $stdout.puts Clippy::VERSION }
9
+ opts.on("-p", "--paste", "Paste") { $stdout.puts Clippy.paste }
10
+ opts.on("-N", "--no-unescape", "Do not unescape \\n") { Clippy.unescape = false }
11
+ opts.on("-v", "--version", "Version") { $stdout.puts Clippy::VERSION }
12
+ opts.on("-C", "--clear", "Clear") { exit Clippy.clear ? 0 : 1 }
13
13
 
14
- opts.on("--copy", "Copy a String or STDIN") do
15
- ($stderr.puts "More than one arg is not allowable" and exit 1) if ARGV.count > 1
16
- exit Clippy.copy(ARGV.count == 0 ? ARGF.readlines.join : ARGV.first.dup) ? 0 : 1
14
+ opts.on("-c", "--copy [STR]", "Copy a String or STDIN") do |str|
15
+ exit (Clippy.copy(str || ARGF.readlines.join) ? 0 : 1)
17
16
  end
18
17
  end.parse!
@@ -7,61 +7,71 @@ if RbConfig::CONFIG["host_os"] =~ /mswin|mingw32/
7
7
  end
8
8
 
9
9
  module Clippy module_function
10
+ @unescape = true
11
+ class << self
12
+ attr_accessor :unescape
13
+ end
14
+
10
15
  class UnknownClipboardError < StandardError
11
16
  def initialize
12
17
  super "Unknown clipboard. Clippy requires xclip, xsel or pbcopy"
13
18
  end
14
19
  end
15
20
 
21
+ def unescape?
22
+ unescape
23
+ end
24
+
16
25
  COMMAND_ARGS = {
17
26
  "xsel" => {
18
- "stdin" => " -ib",
19
- "stdout" => " -ob"
20
- },
27
+ "stdin".freeze => " -ib",
28
+ "stdout".freeze => " -ob"
29
+ }.freeze,
21
30
 
22
31
  "windows" => {
23
- "stdin" => "",
24
- "stdout" => ""
25
- },
32
+ "stdin".freeze => "".freeze,
33
+ "stdout".freeze => "".freeze
34
+ }.freeze,
26
35
 
27
36
  "pbcopy" => {
28
- "stdin" => "",
29
- "stdout" => ""
30
- },
37
+ "stdin".freeze => "".freeze,
38
+ "stdout".freeze => "".freeze
39
+ }.freeze,
31
40
 
32
41
  "xclip" => {
33
- "stdin" => " -i -selection clipboard",
34
- "stdout" => " -o -selection clipboard"
35
- }
36
- }
42
+ "stdin".freeze => " -i -selection clipboard",
43
+ "stdout".freeze => " -o -selection clipboard"
44
+ }.freeze
45
+ }.freeze
37
46
 
38
47
  def windows?
39
48
  RbConfig::CONFIG["host_os"] =~ /mswin|mingw32/
40
49
  end
41
50
 
42
51
  def copy(data)
52
+ data = unescape_newline(data) if unescape?
43
53
  data = data.to_s.gsub($/, "\r\n") if $/ != "\r\n"
44
- rtrn = run_command("stdin", data)[0] == 0 ? true : false
54
+ run_command("stdin", data)[0] == 0 ? true : false
45
55
  end
46
56
 
47
57
  def paste
48
58
  if windows?
49
- Win32API.new("user32", "OpenClipboard", "L", "I").call(0)
50
- data = Win32API.new("user32", "GetClipboardData", "I", "P").call(1) || ""
51
- Win32API.new("user32", "CloseClipboard", [], "I").call
59
+ Win32API.new("user32".freeze, "OpenClipboard", "L", "I").call(0)
60
+ Win32API.new("user32".freeze, "GetClipboardData", "I", "P").call(1) || "".freeze
61
+ Win32API.new("user32".freeze, "CloseClipboard", [], "I").call
52
62
  else
53
- cmd = run_command("stdout")
63
+ cmd = run_command("stdout".freeze)
54
64
  cmd[0] == 0 ? ((cmd[1].nil? || cmd[1].empty?) ? nil : cmd[1]) : false
55
65
  end
56
66
  end
57
67
 
58
68
  def clear
59
- (copy("").nil?) ? true : false
69
+ (copy("".freeze).nil?) ? true : false
60
70
  end
61
71
 
62
72
  def binary
63
73
  @binary ||= if windows?
64
- "clip"
74
+ "clip".freeze
65
75
  else
66
76
  case true
67
77
  when system("which xclip > /dev/null 2>&1") then "xclip"
@@ -73,9 +83,9 @@ module Clippy module_function
73
83
  end
74
84
  end
75
85
 
76
- def run_command(type, data = '')
86
+ def run_command(type, data = "")
77
87
  i, o, e, p = Open3.popen3(binary + COMMAND_ARGS[binary][type])
78
- type == "stdin" ? i.puts(data) : out = o.read.strip
88
+ type == "stdin" ? i.print(data) : out = o.read.strip
79
89
 
80
90
  [i, o, e].each do |m|
81
91
  m.close
@@ -86,4 +96,8 @@ module Clippy module_function
86
96
  type == "stdin" ? data : out
87
97
  ]
88
98
  end
99
+
100
+ def unescape_newline(data)
101
+ data.gsub(/\\n/, "\n").gsub(/\\r/, "\r")
102
+ end
89
103
  end
@@ -1,3 +1,3 @@
1
1
  module Clippy
2
- VERSION = "2.2.1"
2
+ VERSION = "2.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clippy
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordon Bedwell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-17 00:00:00.000000000 Z
11
+ date: 2015-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -87,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  version: '0'
88
88
  requirements: []
89
89
  rubyforge_project:
90
- rubygems_version: 2.4.8
90
+ rubygems_version: 2.5.0
91
91
  signing_key:
92
92
  specification_version: 4
93
93
  summary: A utility to access the systems clipboard.