jbarnette-pastejour 1.0.0.200808041733
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.
- data/README.rdoc +64 -0
- data/Rakefile +54 -0
- data/bin/pastejour +22 -0
- data/lib/pastejour/version.rb +5 -0
- data/lib/pastejour.rb +98 -0
- data/spec/helper.rb +11 -0
- data/spec/pastejour/pastejour_spec.rb +7 -0
- data/spec/spec.opts +7 -0
- metadata +71 -0
data/README.rdoc
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
= Pastejour
|
2
|
+
|
3
|
+
Broadcast standard out using Bonjour.
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
sudo gem install dnssd
|
8
|
+
sudo gem install jbarnette-pastejour --source=http://gems.github.com
|
9
|
+
|
10
|
+
== Usage
|
11
|
+
|
12
|
+
alice$ git diff | pastejour
|
13
|
+
bob$ pastejour alice
|
14
|
+
|
15
|
+
alice$ git diff | pastejour bob
|
16
|
+
bob$ pastejour
|
17
|
+
|
18
|
+
alice$ git diff | pastejour monkeys
|
19
|
+
bob$ pastejour alice-monkeys
|
20
|
+
|
21
|
+
alice$ git diff | pastejour monkeys
|
22
|
+
bob$ pastejour -f
|
23
|
+
Searching for servers (3 seconds)
|
24
|
+
alice-monkeys
|
25
|
+
|
26
|
+
# Copy the clipboard contents from one machine to another
|
27
|
+
alice$ pbpaste | pastejour
|
28
|
+
bob$ pastejour | pbcopy
|
29
|
+
|
30
|
+
== ORLY?
|
31
|
+
|
32
|
+
Yup. Pastejour gives you a simple, discoverable pipe for standard in and
|
33
|
+
out. By default, Pastejour will only stay up until the first person
|
34
|
+
grabs your paste. If you want to let a bunch of people grab the same
|
35
|
+
thing, shoot it out in multiple mode:
|
36
|
+
|
37
|
+
alice$ git diff | pastejour -m # keeps on serving 'til you CTRL-C
|
38
|
+
|
39
|
+
== Awesome!
|
40
|
+
|
41
|
+
You know it.
|
42
|
+
|
43
|
+
== License
|
44
|
+
|
45
|
+
Copyright (c) 2008 John Barnette, Evan Phoenix
|
46
|
+
|
47
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
48
|
+
a copy of this software and associated documentation files (the
|
49
|
+
"Software"), to deal in the Software without restriction, including
|
50
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
51
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
52
|
+
permit persons to whom the Software is furnished to do so, subject to
|
53
|
+
the following conditions:
|
54
|
+
|
55
|
+
The above copyright notice and this permission notice shall be
|
56
|
+
included in all copies or substantial portions of the Software.
|
57
|
+
|
58
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
59
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
60
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
61
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
62
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
63
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
64
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require "date"
|
2
|
+
require "fileutils"
|
3
|
+
require "rubygems"
|
4
|
+
require "rake/gempackagetask"
|
5
|
+
require "spec/rake/spectask"
|
6
|
+
|
7
|
+
require "./lib/pastejour/version.rb"
|
8
|
+
|
9
|
+
pastejour_gemspec = Gem::Specification.new do |s|
|
10
|
+
s.name = "pastejour"
|
11
|
+
s.version = Pastejour::VERSION
|
12
|
+
s.platform = Gem::Platform::RUBY
|
13
|
+
s.has_rdoc = true
|
14
|
+
s.extra_rdoc_files = ["README.rdoc"]
|
15
|
+
s.summary = "Broadcast standard out."
|
16
|
+
s.description = s.summary
|
17
|
+
s.authors = ["John Barnette", "Evan Phoenix"]
|
18
|
+
s.email = "jbarnette@rubyforge.org"
|
19
|
+
s.homepage = "http://github.com/jbarnette/pastejour"
|
20
|
+
s.require_path = "lib"
|
21
|
+
s.autorequire = "pastejour"
|
22
|
+
s.files = %w(README.rdoc Rakefile) + Dir.glob("{bin,lib,spec}/**/*")
|
23
|
+
s.executables = %w(pastejour)
|
24
|
+
|
25
|
+
s.add_dependency "dnssd", ">= 0.6.0"
|
26
|
+
end
|
27
|
+
|
28
|
+
Rake::GemPackageTask.new(pastejour_gemspec) do |pkg|
|
29
|
+
pkg.gem_spec = pastejour_gemspec
|
30
|
+
end
|
31
|
+
|
32
|
+
namespace :gem do
|
33
|
+
desc "Update pastejour.gemspec"
|
34
|
+
task :spec do
|
35
|
+
File.open("pastejour.gemspec", "w") do |f|
|
36
|
+
f.puts(pastejour_gemspec.to_ruby)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
task :install => :package do
|
42
|
+
sh %{sudo gem install --local pkg/pastejour-#{Pastejour::VERSION}}
|
43
|
+
end
|
44
|
+
|
45
|
+
desc "Run all specs"
|
46
|
+
Spec::Rake::SpecTask.new do |t|
|
47
|
+
t.spec_files = FileList["spec/**/*_spec.rb"]
|
48
|
+
t.spec_opts = ["--options", "spec/spec.opts"]
|
49
|
+
end
|
50
|
+
|
51
|
+
task :default => :spec
|
52
|
+
|
53
|
+
desc "Remove all generated artifacts"
|
54
|
+
task :clean => :clobber_package
|
data/bin/pastejour
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "pastejour"
|
5
|
+
|
6
|
+
multiple = ARGV.delete("-m")
|
7
|
+
find = ARGV.delete("-f")
|
8
|
+
teeing = ARGV.delete("-t") || false
|
9
|
+
name = ARGV.shift
|
10
|
+
|
11
|
+
if find
|
12
|
+
Pastejour.list
|
13
|
+
elsif $stdin.tty?
|
14
|
+
name = /#{ENV["USER"]}$/ if name.nil? || name.empty?
|
15
|
+
$stdout.write(Pastejour.get(name))
|
16
|
+
$stdout.flush
|
17
|
+
else
|
18
|
+
name = [ENV["USER"], name].compact.join("-")
|
19
|
+
contents = $stdin.read
|
20
|
+
Pastejour.serve(name, multiple, contents)
|
21
|
+
puts contents if teeing
|
22
|
+
end
|
data/lib/pastejour.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
require "dnssd"
|
2
|
+
require "set"
|
3
|
+
require "socket"
|
4
|
+
require "webrick"
|
5
|
+
|
6
|
+
require "pastejour/version"
|
7
|
+
|
8
|
+
Thread.abort_on_exception = true
|
9
|
+
|
10
|
+
module Pastejour
|
11
|
+
include Socket::Constants
|
12
|
+
|
13
|
+
Paste = Struct.new(:name, :host, :port)
|
14
|
+
PORT = 42424
|
15
|
+
SERVICE = "_pastejour._tcp"
|
16
|
+
|
17
|
+
def self.list
|
18
|
+
servers = {}
|
19
|
+
service = DNSSD.browse(SERVICE) do |reply|
|
20
|
+
servers[reply.name] ||= reply
|
21
|
+
end
|
22
|
+
STDERR.puts "Searching for servers (3 seconds)"
|
23
|
+
# Wait for something to happen
|
24
|
+
sleep 3
|
25
|
+
service.stop
|
26
|
+
servers.each { |string,obj|
|
27
|
+
name, port = string.split ":"
|
28
|
+
STDERR.puts "Found pastejour at '#{name}'"
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def self.find(name, first=true)
|
34
|
+
hosts = Set.new
|
35
|
+
|
36
|
+
waiting = Thread.current
|
37
|
+
|
38
|
+
service = DNSSD.browse(SERVICE) do |reply|
|
39
|
+
if name === reply.name
|
40
|
+
DNSSD.resolve(reply.name, reply.type, reply.domain) do |rr|
|
41
|
+
hosts << Paste.new(reply.name, rr.target, rr.port)
|
42
|
+
waiting.run if first
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
sleep 5
|
48
|
+
service.stop
|
49
|
+
|
50
|
+
hosts
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.get(name)
|
54
|
+
hosts = find(name)
|
55
|
+
|
56
|
+
if hosts.empty?
|
57
|
+
STDERR.puts "ERROR: Unable to find #{name}"
|
58
|
+
elsif hosts.size > 1
|
59
|
+
STDERR.puts "ERROR: Multiple possibles found:"
|
60
|
+
hosts.each do |host|
|
61
|
+
STDERR.puts " #{host.name} (#{host.host}:#{host.port})"
|
62
|
+
end
|
63
|
+
else
|
64
|
+
# Set is weird. There is no #[] or #at
|
65
|
+
hosts.each do |host|
|
66
|
+
STDERR.puts "(#{host.name} from #{host.host}:#{host.port})"
|
67
|
+
sock = TCPSocket.open host.host, host.port
|
68
|
+
return sock.read
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.serve(name, multiple, contents)
|
74
|
+
tr = DNSSD::TextRecord.new
|
75
|
+
tr["description"] = "A paste."
|
76
|
+
|
77
|
+
DNSSD.register(name, SERVICE, "local", PORT, tr.encode) do |reply|
|
78
|
+
STDERR.puts "Pasting #{name}..."
|
79
|
+
end
|
80
|
+
|
81
|
+
log = WEBrick::Log.new(true) # true fools it
|
82
|
+
def log.log(*anything); end # send it to the abyss
|
83
|
+
|
84
|
+
server = WEBrick::GenericServer.new(:Port => PORT, :Logger => log)
|
85
|
+
|
86
|
+
%w(INT TERM).each do |signal|
|
87
|
+
trap signal do
|
88
|
+
server.shutdown
|
89
|
+
exit!
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
server.start do |socket|
|
94
|
+
socket.print(contents)
|
95
|
+
server.shutdown unless multiple
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
data/spec/helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.expand_path("#{File.dirname(__FILE__)}/../lib"))
|
2
|
+
|
3
|
+
require "spec"
|
4
|
+
require "pastejour"
|
5
|
+
|
6
|
+
module Spec::Expectations::ObjectExpectations
|
7
|
+
alias_method :must, :should
|
8
|
+
alias_method :must_not, :should_not
|
9
|
+
undef_method :should
|
10
|
+
undef_method :should_not
|
11
|
+
end
|
data/spec/spec.opts
ADDED
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jbarnette-pastejour
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0.200808041733
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Barnette
|
8
|
+
- Evan Phoenix
|
9
|
+
autorequire: pastejour
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2008-08-04 00:00:00 -07:00
|
14
|
+
default_executable: pastejour
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: dnssd
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.6.0
|
24
|
+
version:
|
25
|
+
description: Broadcast standard out.
|
26
|
+
email: jbarnette@rubyforge.org
|
27
|
+
executables:
|
28
|
+
- pastejour
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README.rdoc
|
33
|
+
files:
|
34
|
+
- README.rdoc
|
35
|
+
- Rakefile
|
36
|
+
- bin/pastejour
|
37
|
+
- lib/pastejour
|
38
|
+
- lib/pastejour/version.rb
|
39
|
+
- lib/pastejour.rb
|
40
|
+
- spec/helper.rb
|
41
|
+
- spec/pastejour
|
42
|
+
- spec/pastejour/pastejour_spec.rb
|
43
|
+
- spec/spec.opts
|
44
|
+
has_rdoc: true
|
45
|
+
homepage: http://github.com/jbarnette/pastejour
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
version:
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "0"
|
62
|
+
version:
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.2.0
|
67
|
+
signing_key:
|
68
|
+
specification_version: 2
|
69
|
+
summary: Broadcast standard out.
|
70
|
+
test_files: []
|
71
|
+
|