Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Gram SSH: Share your clipboard through SSH with your friends

  • Loading branch information...
commit 8c835acf80c7733e9901cf6ff2aec27b5c81ad97 1 parent 30e803e
@txus txus authored
View
2  Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- gram (0.1.0)
+ gram (0.2.0)
activesupport
i18n
rest-client
View
17 Readme.md
@@ -41,6 +41,23 @@ just use the `--rails` option:
This will add the required dependencies and enable the test suite to use
ActiveRecord with in-memory sqlite :)
+##SSH component
+
+Put your peers in your `.gramrc`:
+
+ token: 289347287365872whatever
+ peers:
+ john: 192.168.1.43
+ jimmy: 192.168.1.99
+
+To paste your clipboard's content to your peer's:
+
+ $ gram ssh paste john
+
+You can also broadcast your clipboard's content to all your peers:
+
+ $ gram ssh broadcast
+
## Copyright
Copyright (c) 2011 Codegram. See LICENSE for details.
View
4 lib/gram.rb
@@ -4,6 +4,8 @@
require 'gram/gem'
require 'gram/gem/generator'
+require 'gram/ssh'
+
module Gram
- COMPONENTS = %w(blog gem)
+ COMPONENTS = %w(blog gem ssh)
end
View
62 lib/gram/ssh.rb
@@ -0,0 +1,62 @@
+module Gram
+ module Ssh
+
+ ACTIONS = { paste: {
+ description: "Pastes the current clipboard content to your PEER's clipboard.",
+ arguments: %w(PEER),
+ },
+ broadcast: {
+ description: "Pastes the current clipboard content to all your peers.",
+ arguments: %w(),
+ }
+ }
+
+ class << self
+
+ def banner
+ out = "Available actions:\n"
+ ACTIONS.each_pair do |action, metadata|
+ out << "\n\t#{action} #{metadata[:arguments].join(' ')}\t\t#{metadata[:description]}"
+ end
+
+ peers = nil
+ if File.exists?(File.join(File.expand_path('~'), '.gramrc')) &&
+ peers = YAML.load(File.read(File.join(File.expand_path('~'), '.gramrc')))["peers"]
+ out << "\nYour peers are currently: #{peers.keys.join(', ')}"
+ else
+ out << "\nYou don't have any peers on your ~/.gramrc. Please add some!"
+ end
+
+ out
+ end
+
+ # ACTIONS
+
+ def paste(peer)
+ ip = get_peers[peer]
+ puts "Gram::SSH posting \"#{`pbpaste`}\" to #{peer} at #{ip}..."
+ system("pbpaste | ssh #{peer}@#{ip} pbcopy")
+ puts "Ok!"
+ end
+
+ def broadcast
+ get_peers.keys.each do |peer|
+ paste peer
+ end
+ end
+
+ private
+
+ def get_peers
+ if File.exists?(File.join(File.expand_path('~'), '.gramrc')) &&
+ peers = YAML.load(File.read(File.join(File.expand_path('~'), '.gramrc')))["peers"]
+ peers
+ else
+ puts "Can't get Gram SSH peers. Please create a ~/.gramrc YAML file with some peers."
+ exit(1)
+ end
+ end
+
+ end
+ end
+end
View
2  lib/gram/version.rb
@@ -1,3 +1,3 @@
module Gram
- VERSION = '0.2.0'
+ VERSION = '0.3.0'
end
View
27 spec/gram/ssh_spec.rb
@@ -0,0 +1,27 @@
+require 'spec_helper'
+
+module Gram
+ describe Ssh do
+
+ describe ".paste" do
+ it 'pastes a post to a peer' do
+ subject.stub(:get_peers).and_return({"josepjaume" => "192.168.1.55.55"})
+ subject.should_receive(:system).with("pbpaste | ssh josepjaume@192.168.1.55.55 pbcopy")
+
+ subject.paste 'josepjaume'
+ end
+ end
+
+ describe ".broadcast" do
+ it 'pastes a post to every peer' do
+ subject.stub(:get_peers).and_return({"josepjaume" => "192.168.1.55.55", "oriol" => "192.168.1.55.54"})
+
+ subject.should_receive(:paste).with("josepjaume")
+ subject.should_receive(:paste).with("oriol")
+
+ subject.broadcast
+ end
+ end
+
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.