Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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).
share|improve this answer
    
Thank you for the detailed explanation, I consider this the perfect answer! Maybe I will file a feature request for this. –  padde 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 at 15:42
    
@Chris: Do you know if the bug that you have mentioned above is fixed in 1.9? –  Behrang Mar 10 at 11:56
    
@Behrang: The behavior seems to be unchanged as of version 1.9a. –  Chris Johnsen Mar 10 at 12:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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