clippy 2.0.7 → 2.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +8 -5
- data/Rakefile +1 -1
- data/lib/clippy.rb +31 -31
- data/lib/clippy/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c00c52bc78c01fd0eb59cfc5ddb26729a9e0dc2
|
4
|
+
data.tar.gz: 62d4bb2f9e8c60064c8e2de5acee932cedef4e3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9551db53c413d90235f4b5b931ec97163b87d406c7d80f09b456b9798d043ae6406b21e557fdcb6bc90dedf4c6ac00bfcdfeeb75a702743c1d92a37e2df121af
|
7
|
+
data.tar.gz: b28994927786f62c93e567130e32894dd0a7094e77bdd7681352c3f45e8688215df2dafd80fd8312c03d5ca07f2254ee0430d17fef99766f85d19da57d70ec14
|
data/Gemfile
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
-
source
|
1
|
+
source "https://rubygems.org"
|
2
2
|
gemspec
|
3
3
|
|
4
4
|
group :development do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
unless ENV["CI"]
|
6
|
+
gem "pry"
|
7
|
+
end
|
8
|
+
|
9
|
+
gem "rake"
|
10
|
+
gem "envygeeks-coveralls"
|
11
|
+
gem "luna-rspec-formatters"
|
9
12
|
end
|
data/Rakefile
CHANGED
data/lib/clippy.rb
CHANGED
@@ -1,71 +1,71 @@
|
|
1
|
-
require_relative
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require_relative "clippy/version"
|
2
|
+
require "rbconfig"
|
3
|
+
require "open3"
|
4
4
|
|
5
|
-
if RbConfig::CONFIG[
|
6
|
-
require
|
5
|
+
if RbConfig::CONFIG["host_os"] =~ /mswin|mingw32/
|
6
|
+
require "Win32API"
|
7
7
|
end
|
8
8
|
|
9
9
|
module Clippy module_function
|
10
10
|
class UnknownClipboardError < StandardError
|
11
11
|
def initialize
|
12
|
-
super
|
12
|
+
super "Unknown clipboard. Clippy requires xclip, xsel or pbcopy"
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
COMMAND_ARGS = {
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
"xsel" => {
|
18
|
+
"stdin" => " -ib",
|
19
|
+
"stdout" => " -ob"
|
20
20
|
},
|
21
21
|
|
22
|
-
|
23
|
-
"stdin" =>
|
24
|
-
"stdout" =>
|
22
|
+
"windows" => {
|
23
|
+
"stdin" => "",
|
24
|
+
"stdout" => ""
|
25
25
|
},
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
"pbcopy" => {
|
28
|
+
"stdin" => "",
|
29
|
+
"stdout" => ""
|
30
30
|
},
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
"xclip" => {
|
33
|
+
"stdin" => " -i -selection clipboard",
|
34
|
+
"stdout" => " -o -selection clipboard"
|
35
35
|
}
|
36
36
|
}
|
37
37
|
|
38
38
|
def windows?
|
39
|
-
RbConfig::CONFIG[
|
39
|
+
RbConfig::CONFIG["host_os"] =~ /mswin|mingw32/
|
40
40
|
end
|
41
41
|
|
42
42
|
def copy(data)
|
43
|
-
run_command(
|
43
|
+
run_command("stdin", $/ != "\r\n" ? data.to_s.gsub($/, "\r\n") : data)[0] == 0 ? true : false
|
44
44
|
end
|
45
45
|
|
46
46
|
def paste
|
47
47
|
if windows?
|
48
|
-
Win32API.new(
|
49
|
-
data = Win32API.new(
|
50
|
-
Win32API.new(
|
48
|
+
Win32API.new("user32", "OpenClipboard", "L", "I").call(0)
|
49
|
+
data = Win32API.new("user32", "GetClipboardData", "I", "P").call(1) || ""
|
50
|
+
Win32API.new("user32", "CloseClipboard", [], "I").call
|
51
51
|
else
|
52
|
-
cmd = run_command(
|
52
|
+
cmd = run_command("stdout")
|
53
53
|
cmd[0] == 0 ? ((cmd[1].nil? || cmd[1].empty?) ? nil : cmd[1]) : false
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
57
|
def clear
|
58
|
-
(copy(
|
58
|
+
(copy("").nil?) ? true : false
|
59
59
|
end
|
60
60
|
|
61
61
|
def binary
|
62
62
|
@binary ||= if windows?
|
63
|
-
|
63
|
+
"clip"
|
64
64
|
else
|
65
65
|
case true
|
66
|
-
when system(
|
67
|
-
when system(
|
68
|
-
when system(
|
66
|
+
when system("which xclip > /dev/null 2>&1") then "xclip"
|
67
|
+
when system("which xsel > /dev/null 2>&1") then "xsel"
|
68
|
+
when system("which pbcopy > /dev/null 2>&1") then "pbcopy"
|
69
69
|
else
|
70
70
|
raise UnknownClipboardError
|
71
71
|
end
|
@@ -74,7 +74,7 @@ module Clippy module_function
|
|
74
74
|
|
75
75
|
def run_command(type, data = '')
|
76
76
|
stdin, stdout, stderr, pid = Open3.popen3(binary + COMMAND_ARGS[binary][type])
|
77
|
-
type ==
|
77
|
+
type == "stdin" ? stdin.puts(data) : out = stdout.read.strip
|
78
78
|
|
79
79
|
[stdin, stdout, stderr].each do |m|
|
80
80
|
m.close
|
@@ -82,7 +82,7 @@ module Clippy module_function
|
|
82
82
|
|
83
83
|
[
|
84
84
|
pid.value,
|
85
|
-
type ==
|
85
|
+
type == "stdin" ? data : out
|
86
86
|
]
|
87
87
|
end
|
88
88
|
end
|
data/lib/clippy/version.rb
CHANGED