Sha256: 7a6bc5f5858f1feab788cd34106ea882ed5c784022ebcc7082cf063ea3066f59

Contents?: true

Size: 1.69 KB

Versions: 1

Compression:

Stored size: 1.69 KB

Contents

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gram-0.3.0 lib/gram/ssh.rb