Module: Gram::Ssh

Defined in:
lib/gram/ssh.rb

Constant Summary collapse

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 Method Summary collapse

Class Method Details



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/gram/ssh.rb', line 16

def banner
  out = "Available actions:\n"
  ACTIONS.each_pair do |action, |
    out << "\n\t#{action} #{[:arguments].join(' ')}\t\t#{[: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

.broadcastObject



42
43
44
45
46
# File 'lib/gram/ssh.rb', line 42

def broadcast
  get_peers.keys.each do |peer|
    paste peer
  end
end

.paste(peer) ⇒ Object

ACTIONS



35
36
37
38
39
40
# File 'lib/gram/ssh.rb', line 35

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