0

For my current project, most work happens in tmux on a remote system. Sometimes, I would like to copy text from the remote system to my local machine (i.e. for sending email). My current workflow is

  • Enter tmux copy mode and copy text
  • Run :save-buffer ~/clipboard in tmux
  • On my local machine, I have a command aliased to ssh remote-machine 'cat ~/clipboard' | pbcopy

This is a huge pain, and I'm wondering if there's a way to run a script in copy mode. Specifically, is there a way I can bind the command :save-buffer ~/clipboard to pressing Enter in copy mode? (or maybe on buffer update?)

The machine I am ssh'ing into the remote machine from is not constant, so it's ok if I still have to run the command on my mac.

1

When in copy-mode, you can use copy-pipe <command>, with a command such as cat > ~/clipboard.

In Tmux 2.5 or later, you can bind that to Enter with

bind-key -T copy-mode Enter send-keys -X copy-pipe "cat > ~/clipboard"

(or -T copy-mode-vi, depending on your mode-keys setting)

See also: copy paste functionality with xclip non functional

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.