I use copy-pipe on OS X to share the system clipboard with Tmux 1.8:

unbind -t vi-copy Enter
bind -t vi-copy Enter copy-pipe "reattach-to-user-namespace pbcopy"

This works when entering select mode and copying text (select text, then hit Enter), but not when selecting text with the mouse. Is it possible to set a command that should run after mouse selection, just like copy-pipe runs after hitting Enter? I.e. I need to run reattach-to-user-namespace pbcopy when the selection is left.


There is no built-in way to customize the “mouse up” behavior that ends a selection that was started by the mouse. For the details, see the reset_mode label of window_copy_mouse() in window-copy.c (links are to the source of tmux 1.8); specifically, there are no references to window, session, or server options in this bit of code.

There is a workaround, but it is probably a bit of an edge case:

  • Activate your copy-pipe binding (e.g. press Enter) before releasing the mouse button.
    This will run your shell command, copy the selection into a buffer, and exit copy mode (i.e. the usual behavior for copy-pipe).

There is a small side effect though:

  • The mouse event that your terminal will send when you finally release the button will cause tmux to re-enter copy mode. You will need to manually exit (e.g. Escape or C-c) this “extra” copy mode.
    This could probably be considered a bug (input_mouse() does not check that the mouse event is a “button up” event before starting a new copy mode); but, it is mostly harmless (other than the inconvenience of having to exit the second copy mode instance).
  • Thank you for the detailed explanation, I consider this the perfect answer! Maybe I will file a feature request for this. – Patrick Oscity Oct 30 '13 at 16:12
  • It's possible for mouse selection to work without any of these shenanigans. I use iTerm 2, OSX Mavericks, and tmux 1.8, and any text I select in tmux (real tmux selection, not a terminal selection) is copied to the system clipboard. Alas, it works on one of my machines and not another (same versions of everything), and I can't for the life of me figure out why...but it's possible. I'll post my config once I figure out how to get it working on both. – Jim Stewart Jan 30 '14 at 15:42
  • @Chris: Do you know if the bug that you have mentioned above is fixed in 1.9? – Behrang Mar 10 '14 at 11:56
  • @Behrang: The behavior seems to be unchanged as of version 1.9a. – Chris Johnsen Mar 10 '14 at 12:16
  • 1
    @muffel: Right, 2.0 does not appear to change that; it is 2.1 (still in development/unreleased) that will change that particular behavior. – Chris Johnsen Jul 9 '15 at 5:18

For tmux 2.2 and later use:

bind-key -t emacs-copy MouseDragEnd1Pane copy-pipe "pbcopy"
bind-key -t vi-copy MouseDragEnd1Pane copy-pipe "pbcopy"

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.