nwcopy 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +16 -5
- data/bin/nwcopy +6 -3
- data/bin/nwpaste +6 -3
- data/lib/nwcopy.rb +32 -33
- data/lib/nwcopy/dropbox.rb +61 -0
- data/lib/nwcopy/version.rb +1 -1
- metadata +3 -2
data/README.rdoc
CHANGED
@@ -5,17 +5,25 @@ The fool proof network copy & paste program. Well, maybe someday.
|
|
5
5
|
= Usage
|
6
6
|
|
7
7
|
> nwcopy
|
8
|
-
|
8
|
+
/Users/josh/Dropbox/nwcopy/f314eee55161b14f140ee07b358ba63ef54112ac
|
9
9
|
> nwpaste
|
10
|
-
Clipboard now contains
|
11
10
|
https://github.com/j05h/nwcopy
|
12
11
|
|
12
|
+
> nwcopy /path/to/file
|
13
|
+
/Users/josh/Dropbox/nwcopy/e1c1675f009e65d8571bbab9243660da20a3b2a2
|
14
|
+
> nwpaste
|
15
|
+
Contents of file
|
16
|
+
|
17
|
+
> echo 'pipes work' | nwcopy
|
18
|
+
/Users/josh/Dropbox/nwcopy/5293e79627710caf507fb9b841df51356650c78d
|
19
|
+
> nwpaste
|
20
|
+
pipes work
|
13
21
|
|
14
22
|
= Description
|
15
23
|
|
16
|
-
nwcopy takes whatever is in the clipboard and copies it to a file in your Dropbox folder ~/Dropbox/nwcopy/<sha1>
|
24
|
+
nwcopy takes whatever is in the clipboard (or pipe or filename) and copies it to a file in your Dropbox folder ~/Dropbox/nwcopy/<sha1>
|
17
25
|
|
18
|
-
nwpaste takes the contents of the most recent file and puts it in the clipboard.
|
26
|
+
nwpaste takes the contents of the most recent file, prints it to STDIN and puts it in the clipboard.
|
19
27
|
|
20
28
|
= WTF?
|
21
29
|
|
@@ -27,6 +35,9 @@ I constantly want to copy and paste between machines which cannot directly talk
|
|
27
35
|
|
28
36
|
Is that all? Well, yeah, right now. This is the initial version, and it works! However, here are my plans:
|
29
37
|
|
30
|
-
*
|
38
|
+
* Write some tests
|
39
|
+
* Support multiple files with globbing and whatnot.
|
40
|
+
* When files are supplied, they should be pasted back with their original filename (tarball?)
|
41
|
+
* Integrate with github/pastebin/skitch/etc so that you don't need a Dropbox account.
|
31
42
|
* Add a server component which can be easily used with curl.
|
32
43
|
* Have some delicious brisket.
|
data/bin/nwcopy
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require File.join(File.dirname(__FILE__), '..', 'lib/nwcopy')
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib/nwcopy'))
|
4
4
|
|
5
|
-
file = Nwcopy.copy
|
6
|
-
puts
|
5
|
+
if file = Nwcopy.copy
|
6
|
+
puts file
|
7
|
+
else
|
8
|
+
puts "No data copied"
|
9
|
+
end
|
data/bin/nwpaste
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require File.join(File.dirname(__FILE__), '..', 'lib/nwcopy')
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib/nwcopy'))
|
4
4
|
|
5
|
-
data = Nwcopy.paste
|
6
|
-
puts
|
5
|
+
if data = Nwcopy.paste
|
6
|
+
puts data
|
7
|
+
else
|
8
|
+
puts "No data pasted"
|
9
|
+
end
|
data/lib/nwcopy.rb
CHANGED
@@ -1,44 +1,43 @@
|
|
1
|
-
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) ||
|
3
|
+
$:.include?(File.expand_path(File.dirname(__FILE__)))
|
2
4
|
|
3
|
-
|
4
|
-
def self.dropbox_dir
|
5
|
-
File.expand_path '~/Dropbox'
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.nwcopy_dir
|
9
|
-
File.join dropbox_dir, 'nwcopy'
|
10
|
-
end
|
5
|
+
require 'nwcopy/dropbox'
|
11
6
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
puts "Creating nwcopy directory at #{nwcopy_dir}"
|
20
|
-
Dir.mkdir nwcopy_dir
|
7
|
+
module Nwcopy
|
8
|
+
def self.copy
|
9
|
+
data = read_data
|
10
|
+
if Nwcopy::Dropbox.available?
|
11
|
+
Nwcopy::Dropbox.copy data
|
12
|
+
else
|
13
|
+
STDERR << NwCopy::Dropbox.unavailable_message
|
21
14
|
end
|
22
15
|
end
|
23
16
|
|
24
|
-
def self.
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
17
|
+
def self.paste
|
18
|
+
if Nwcopy::Dropbox.available?
|
19
|
+
if clipboard = Nwcopy::Dropbox.paste
|
20
|
+
`echo "#{clipboard}" | pbcopy` unless `which pbcopy`.empty?
|
21
|
+
clipboard
|
22
|
+
end
|
23
|
+
else
|
24
|
+
STDERR << NwCopy::Dropbox.unavailable_message
|
29
25
|
end
|
30
|
-
nwcopy_file
|
31
26
|
end
|
32
27
|
|
33
|
-
|
34
|
-
|
35
|
-
|
28
|
+
private
|
29
|
+
def self.read_data
|
30
|
+
if ARGF.file == STDIN
|
31
|
+
STDIN.read_nonblock(1) + STDIN.read
|
32
|
+
else
|
33
|
+
ARGF.read
|
34
|
+
end
|
35
|
+
rescue IO::WaitReadable => e
|
36
|
+
unless `which pbpaste`.empty?
|
37
|
+
`pbpaste`
|
38
|
+
else
|
39
|
+
STDERR << 'Nothing to do!'
|
36
40
|
end
|
37
|
-
|
38
|
-
clipboard = File.new(files.first).read
|
39
|
-
`echo #{clipboard} | pbcopy`
|
40
|
-
clipboard
|
41
41
|
end
|
42
|
-
end
|
43
42
|
|
44
|
-
|
43
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'digest/sha1'
|
2
|
+
|
3
|
+
module Nwcopy
|
4
|
+
class Dropbox
|
5
|
+
def self.unavailable_message
|
6
|
+
"Dropbox was not found at #{nwcopy_dir}. Get it at http://getdropbox.com/"
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.available?
|
10
|
+
return false unless File.exists? dropbox_dir
|
11
|
+
|
12
|
+
unless File.exists? nwcopy_dir
|
13
|
+
STDERR << "Creating nwcopy directory at #{nwcopy_dir}"
|
14
|
+
Dir.mkdir nwcopy_dir
|
15
|
+
end
|
16
|
+
|
17
|
+
File.exists? nwcopy_dir
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.copy clipboard
|
21
|
+
digest = Digest::SHA1.hexdigest clipboard
|
22
|
+
nwcopy_file = File.join nwcopy_dir, digest
|
23
|
+
File.open(nwcopy_file, 'w+') do |f|
|
24
|
+
f << clipboard
|
25
|
+
end
|
26
|
+
nwcopy_file
|
27
|
+
end
|
28
|
+
|
29
|
+
# Used to determine which plugin has the newest file.
|
30
|
+
def self.time
|
31
|
+
latest_file.mtime
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.paste
|
35
|
+
File.new(latest_file).read
|
36
|
+
end
|
37
|
+
|
38
|
+
private # These methods are not part of the API
|
39
|
+
|
40
|
+
def self.files
|
41
|
+
Dir.glob(File.join(nwcopy_dir,'*')).map do |f|
|
42
|
+
File.new(f)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.latest_file
|
47
|
+
files.sort do |file1, file2|
|
48
|
+
file2.mtime <=> file1.mtime
|
49
|
+
end.first
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.dropbox_dir
|
53
|
+
File.expand_path '~/Dropbox'
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.nwcopy_dir
|
57
|
+
File.join dropbox_dir, 'nwcopy'
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
data/lib/nwcopy/version.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Josh Kleinpeter
|
@@ -36,6 +36,7 @@ files:
|
|
36
36
|
- bin/nwcopy
|
37
37
|
- bin/nwpaste
|
38
38
|
- lib/nwcopy.rb
|
39
|
+
- lib/nwcopy/dropbox.rb
|
39
40
|
- lib/nwcopy/version.rb
|
40
41
|
- nwcopy.gemspec
|
41
42
|
has_rdoc: true
|