clippy 2.3.0 → 3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c6f7e86513ddda4fedd2dabdfa424d290233c390
4
- data.tar.gz: f127557e982d74e3377f7cfb114d81a21b178306
3
+ metadata.gz: 4e0a599bcf0609f227ea4f410b8c71985f2fc977
4
+ data.tar.gz: 3712437c79f801752de32dd27cbfc51b4bd1f2ed
5
5
  SHA512:
6
- metadata.gz: 605f99bab2aa4c37f4a9f80e6c361a4ffe874ca939b6721f20bd672411f8d619649a896d318a1322062ef75f59d186d1ce83ceada9d6271fd970fd16acd732d8
7
- data.tar.gz: e6be611a0a543f328c9b8f184af1d23bd181788f6ec057a55db743659e62e5ce1b9009f24100a9165b7b5aa09500df5699fc4b0b49227915cfc1f28cfe3a1d31
6
+ metadata.gz: 9a583925a8d04905704a7f215934efc6591081a54025a0088187e0af768f7c914417ce3be78d3c6332b98caa64cc970f7cf0104060f78acb8c00b7886a717e3f
7
+ data.tar.gz: 71d05b718ddecd45f3968333e68cb39497a6dc5eb50a5a7fbee4c8661c9e2ab2fb7a3eb3bdf172287d419989c040514989440696d331604101882f631815c293
data/Gemfile CHANGED
@@ -1,7 +1,17 @@
1
1
  source "https://rubygems.org"
2
2
  gemspec
3
3
 
4
+ gem "rake"
5
+ group :test do
6
+ gem "codeclimate-test-reporter", {
7
+ :require => false
8
+ }
9
+ end
10
+
4
11
  group :development do
5
- gem "rake"
6
- gem "pry"
12
+ gem "pry", :require => false
13
+ gem "travis", :require => false
14
+ gem "luna-rspec-formatters", :require => false
15
+ gem "luna-rubocop-formatters", :require => false
16
+ gem "rspec", :require => false
7
17
  end
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011-2015 Jordon Bedwell
1
+ Copyright (c) 2011-2016 Jordon Bedwell
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a
4
4
  copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,7 +1,14 @@
1
1
  Clippy is a cross-platform clipboard utility and script for Ruby.
2
2
 
3
- [![Build Status](https://travis-ci.org/envygeeks/ruby-clippy.png?branch=master)](https://travis-ci.org/envygeeks/ruby-clippy) [![Coverage Status](https://coveralls.io/repos/envygeeks/ruby-clippy/badge.png?branch=master)](https://coveralls.io/r/envygeeks/ruby-clippy) [![Code Climate](https://codeclimate.com/github/envygeeks/ruby-clippy.png)](https://codeclimate.com/github/envygeeks/ruby-clippy) [![Dependency Status](https://gemnasium.com/envygeeks/ruby-clippy.png)](https://gemnasium.com/envygeeks/ruby-clippy)
3
+ [![Build Status](https://travis-ci.org/envygeeks/clippy.svg?branch=master)][travis]
4
+ [![Test Coverage](https://codeclimate.com/github/envygeeks/clippy/badges/coverage.svg)][coverage]
5
+ [![Code Climate](https://codeclimate.com/github/envygeeks/clippy/badges/gpa.svg)][codeclimate]
6
+ [![Dependency Status](https://gemnasium.com/envygeeks/clippy.svg)][gemnasium]
4
7
 
8
+ [gemnasium]: https://gemnasium.com/envygeeks/clippy
9
+ [codeclimate]: https://codeclimate.com/github/envygeeks/clippy
10
+ [coverage]: https://codeclimate.com/github/envygeeks/clippy/coverage
11
+ [travis]: https://travis-ci.org/envygeeks/clippy
5
12
  ---
6
13
  * Requirements:
7
14
  * Windows: `clip`
data/Rakefile CHANGED
@@ -1,5 +1,8 @@
1
+ require "luna/rubocop/rake/task"
1
2
  require "rspec/core/rake_task"
2
3
 
3
4
  task :default => [:spec]
4
5
  task :test => :spec
5
- RSpec::Core::RakeTask.new :spec
6
+ RSpec::Core::RakeTask.new(
7
+ :spec
8
+ )
data/bin/clippy CHANGED
@@ -10,8 +10,7 @@ OptionParser.new do |opts|
10
10
  opts.on("-N", "--no-unescape", "Do not unescape \\n") { Clippy.unescape = false }
11
11
  opts.on("-v", "--version", "Version") { $stdout.puts Clippy::VERSION }
12
12
  opts.on("-C", "--clear", "Clear") { exit Clippy.clear ? 0 : 1 }
13
-
14
13
  opts.on("-c", "--copy [STR]", "Copy a String or STDIN") do |str|
15
- exit (Clippy.copy(str || ARGF.readlines.join) ? 0 : 1)
14
+ exit Clippy.copy(str || ARGF.readlines.join) ? 0 : 1
16
15
  end
17
16
  end.parse!
@@ -1,103 +1,147 @@
1
- require_relative "clippy/version"
2
- require "rbconfig"
3
- require "open3"
4
-
5
- if RbConfig::CONFIG["host_os"] =~ /mswin|mingw32/
6
- require "Win32API"
7
- end
8
-
9
- module Clippy module_function
10
- @unescape = true
11
- class << self
12
- attr_accessor :unescape
13
- end
14
-
15
- class UnknownClipboardError < StandardError
16
- def initialize
17
- super "Unknown clipboard. Clippy requires xclip, xsel or pbcopy"
18
- end
19
- end
20
-
21
- def unescape?
22
- unescape
23
- end
24
-
25
- COMMAND_ARGS = {
26
- "xsel" => {
27
- "stdin".freeze => " -ib",
28
- "stdout".freeze => " -ob"
29
- }.freeze,
30
-
31
- "windows" => {
32
- "stdin".freeze => "".freeze,
33
- "stdout".freeze => "".freeze
34
- }.freeze,
35
-
36
- "pbcopy" => {
37
- "stdin".freeze => "".freeze,
38
- "stdout".freeze => "".freeze
39
- }.freeze,
40
-
41
- "xclip" => {
42
- "stdin".freeze => " -i -selection clipboard",
43
- "stdout".freeze => " -o -selection clipboard"
44
- }.freeze
45
- }.freeze
46
-
47
- def windows?
48
- RbConfig::CONFIG["host_os"] =~ /mswin|mingw32/
49
- end
50
-
51
- def copy(data)
52
- data = unescape_newline(data) if unescape?
53
- data = data.to_s.gsub($/, "\r\n") if $/ != "\r\n"
54
- run_command("stdin", data)[0] == 0 ? true : false
55
- end
56
-
57
- def paste
58
- if windows?
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
62
- else
63
- cmd = run_command("stdout".freeze)
64
- cmd[0] == 0 ? ((cmd[1].nil? || cmd[1].empty?) ? nil : cmd[1]) : false
65
- end
66
- end
67
-
68
- def clear
69
- (copy("".freeze).nil?) ? true : false
70
- end
71
-
72
- def binary
73
- @binary ||= if windows?
74
- "clip".freeze
75
- else
76
- case true
77
- when system("which xclip > /dev/null 2>&1") then "xclip"
78
- when system("which xsel > /dev/null 2>&1") then "xsel"
79
- when system("which pbcopy > /dev/null 2>&1") then "pbcopy"
80
- else
81
- raise UnknownClipboardError
82
- end
83
- end
84
- end
85
-
86
- def run_command(type, data = "")
87
- i, o, e, p = Open3.popen3(binary + COMMAND_ARGS[binary][type])
88
- type == "stdin" ? i.print(data) : out = o.read.strip
89
-
90
- [i, o, e].each do |m|
91
- m.close
92
- end
93
-
94
- [
95
- p.value,
96
- type == "stdin" ? data : out
97
- ]
98
- end
99
-
100
- def unescape_newline(data)
101
- data.gsub(/\\n/, "\n").gsub(/\\r/, "\r")
102
- end
103
- end
1
+
2
+ # Frozen-string-literal: true
3
+ # Copyright: 2015-2016 Jordon Bedwell - MIT License
4
+ # Encoding: utf-8
5
+
6
+ require "English"
7
+ require_relative "clippy/version"
8
+ require "rbconfig"
9
+ require "open3"
10
+
11
+ if RbConfig::CONFIG["host_os"] =~ /mswin|mingw32/
12
+ require "Win32API"
13
+ end
14
+
15
+ module Clippy
16
+ @unescape = true
17
+ module_function
18
+
19
+ # --
20
+
21
+ class << self
22
+ attr_accessor :unescape
23
+ end
24
+
25
+ # --
26
+
27
+ class UnknownClipboardError < StandardError
28
+ def initialize
29
+ super "Unknown clipboard. Clippy requires xclip, xsel or pbcopy"
30
+ end
31
+ end
32
+
33
+ # --
34
+
35
+ def unescape?
36
+ unescape
37
+ end
38
+
39
+ # --
40
+
41
+ COMMAND_ARGS = {
42
+ "xsel" => {
43
+ "stdin" => " -ib",
44
+ "stdout" => " -ob"
45
+ },
46
+
47
+ "windows" => {
48
+ "stdin" => "",
49
+ "stdout" => ""
50
+ },
51
+
52
+ "pbcopy" => {
53
+ "stdin" => "",
54
+ "stdout" => ""
55
+ },
56
+
57
+ "xclip" => {
58
+ "stdin" => " -i -selection clipboard",
59
+ "stdout" => " -o -selection clipboard"
60
+ }
61
+ }.freeze
62
+
63
+ # --
64
+ # Whether or not this is Windows.
65
+ # @return [Fixnum,nil]
66
+ # --
67
+ def windows?
68
+ RbConfig::CONFIG["host_os"] =~ /mswin|mingw32/
69
+ end
70
+
71
+ # --
72
+ # @return [true,false]
73
+ # Copy.
74
+ # --
75
+ def copy(data)
76
+ data = unescape_newline(data) if unescape?
77
+ out = run_command("stdin", data)
78
+ out [0] == 0 ? true : false
79
+ end
80
+
81
+ # --
82
+ # @return [true,false]
83
+ # Paste
84
+ # --
85
+ def paste
86
+ if windows?
87
+ Win32API.new("user32".freeze, "OpenClipboard", "L", "I").call(0)
88
+ Win32API.new("user32".freeze, "GetClipboardData", "I", "P").call(1) || ""
89
+ Win32API.new("user32".freeze, "CloseClipboard", [], "I").call
90
+ else
91
+ cmd = run_command("stdout".freeze)
92
+ cmd[0] != 0 ? false : \
93
+ if cmd[1].nil? || cmd[1].empty?
94
+ then nil else cmd[1]
95
+ end
96
+ end
97
+ end
98
+
99
+ # --
100
+ # @return [true,false]
101
+ # Clear.
102
+ # --
103
+ def clear
104
+ copy("".freeze).nil?? true : false
105
+ end
106
+
107
+ # --
108
+ # Pull out the binary we need to use.
109
+ # rubocop:disable Lint/LiteralInCondition
110
+ # @return [String]
111
+ # --
112
+ def binary
113
+ @binary ||= begin
114
+ if windows?
115
+ "clip".freeze
116
+ else
117
+ case true
118
+ when system("which xclip > /dev/null 2>&1") then "xclip"
119
+ when system("which xsel > /dev/null 2>&1") then "xsel"
120
+ when system("which pbcopy > /dev/null 2>&1") then "pbcopy"
121
+ else
122
+ raise UnknownClipboardError
123
+ end
124
+ end
125
+ end
126
+ end
127
+
128
+ # --
129
+ # Run a command and get the output.
130
+ # rubocop:enable Lint/LiteralInCondition
131
+ # @return [Array]
132
+ # --
133
+ def run_command(type, data = "")
134
+ i, o, e, p = Open3.popen3(binary + COMMAND_ARGS[binary][type])
135
+ type == "stdin" ? i.print(data) : out = o.read.strip
136
+ [i, o, e].map(&:close)
137
+
138
+ [
139
+ p.value,
140
+ type == "stdin" ? data : out
141
+ ]
142
+ end
143
+
144
+ def unescape_newline(data)
145
+ data.gsub(/\\n/, "\n").gsub(/\\r/, "\r")
146
+ end
147
+ end
@@ -1,3 +1,3 @@
1
1
  module Clippy
2
- VERSION = "2.3.0"
2
+ VERSION = "3.0.0"
3
3
  end
metadata CHANGED
@@ -1,57 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clippy
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 3.0.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-11-12 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rspec
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '3.3'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '3.3'
27
- - !ruby/object:Gem::Dependency
28
- name: envygeeks-coveralls
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '1.0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '1.0'
41
- - !ruby/object:Gem::Dependency
42
- name: luna-rspec-formatters
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '3.3'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '3.3'
11
+ date: 2016-05-18 00:00:00.000000000 Z
12
+ dependencies: []
55
13
  description: A utility to access the systems clipboard.
56
14
  email:
57
15
  - jordon@envygeeks.io
@@ -87,7 +45,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
45
  version: '0'
88
46
  requirements: []
89
47
  rubyforge_project:
90
- rubygems_version: 2.5.0
48
+ rubygems_version: 2.6.4
91
49
  signing_key:
92
50
  specification_version: 4
93
51
  summary: A utility to access the systems clipboard.