Kentaro Kuribayashi's blog

Software Engineering, Management, Books, and Daily Journal.

Workaround for tmux + pb(copy|paste) to Use pry-clipboard

I tried to use secondlife's pry-clipboard and found it didn't work well for me.

It was due to tmux + pb(paste|copy) problem described at typester's blog post. I just added some more codes into $HOME/.pryrc like below:

begin
  require 'pry-clipboard'

  # aliases
  Pry.config.commands.alias_command 'ch', 'copy-history'
  Pry.config.commands.alias_command 'cr', 'copy-result'

  # workaround for tmux + pb(copy|paste)
  # http://unknownplace.org/memo/2012/03/27/1/
  module Clipboard::Mac
    require 'open3'

    def paste(_ = nil)
      `ssh 127.0.0.1 pbpaste`
    end

    def copy(data)
      Open3.popen3( 'ssh 127.0.0.1 pbcopy' ){ |input,_,_| input << data }
      paste
    end
  end
rescue LoadError => e
  warn "can't load pry-clipboard"
end

It now works, but a bit slow because of executing pb(paste|copy) via SSH. I'll do with the problem more correctly if I feel trouble indeed against it.