If I select text with a mouse in tmux in iTerm2 on macOS I get the selected text copied into my clipboard. I do not have to click any extra buttons - just select the text you want and you're done.A recording showing the tmux behaviour in iTerm2I've tested tmux in terminal.app on macOS but it doesn't work there - I have to hit y to copy the selection to my clipboard.I thought that there is a mouse binding (something like MouseOnSelection similar to MouseDown1Pane) but I couldn't find anything useful on the web and man tmux.I wonder if there is a way to have a similar behaviour on Ubuntu 16.10 - preferably in the Gnome terminal.My tmux dotfiles are available here (link).
Copy selection to a clipboard in tmux
tmux;clipboard
set-option -g mouse onset-option -s set-clipboard offbind-key -t vi-copy MouseDragEnd1Pane copy-pipe xclip -se c -iExplantion: First we need to enable the mouse option so tmux will capture the mouse, let us bind mouse events, and give us the default bindings that enable dragging:set-option -g mouse onGnome-terminal doesn't support setting the clipboard using xterm escape sequences so we should ensure the set-clipboard option is off:set-option -s set-clipboard offThis option might be supported and enabled by default on iTerm2 (see set-clipboard in the tmux manual), which would explain the behavior on there.In tmux 2.3 we can then bind to the copy-mode MouseDragEnd1Pane key (i.e. when the first mouse button is released after clicking and dragging in a pane) with the copy-pipe command. This will pipe the selected text from copy mode to the given command, in our case to xclip since we want to set the contents of X's clipboard:# For vi copy mode bindingsbind-key -t vi-copy MouseDragEnd1Pane copy-pipe xclip -selection clipboard -i# For emacs copy mode bindingsbind-key -t emacs-copy MouseDragEnd1Pane copy-pipe xclip -selection clipboard -iThis is all we have to do because tmux's default mouse bindings for MouseDrag1Pane take care of translating the mouse drag to a copy-mode selection.Finally, note that the way that bindings to copy-mode commands are made has changed in development versions since 2.3, so for future releases the correct command will be # For vi copy mode bindingsbind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel xclip -selection clipboard -i# For emacs copy mode bindingsbind-key -T copy-mode MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel xclip -selection clipboard -i