#!/usr/bin/env ruby require 'socket' copy_remote_host_port = ENV['COPY_REMOTE_HOST_PORT'] and copy_remote_host_port =~ /\A([^:]+):([^:]+)\z/ or fail "environment variable COPY_REMOTE_HOST_PORT of form host:port required" copy_remote_host, copy_remote_port = $1, $2 clipboard = TCPSocket.new(copy_remote_host, copy_remote_port) until STDIN.eof? clipboard.write STDIN.read(1 << 16) end