Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yank default action for TMUX > 2.4 + MouseDragEnd1Pane #104

Merged
merged 2 commits into from
Mar 18, 2018
Merged

yank default action for TMUX > 2.4 + MouseDragEnd1Pane #104

merged 2 commits into from
Mar 18, 2018

Conversation

kaliberr44
Copy link

Added @yank_action for user to be able to choose copy-pipe or copy-pipe-and-cancel when yanking without put.

Also added MouseDragEnd1Pane so you don't have to press y after selecting with mouse.

@maximbaz
Copy link
Contributor

maximbaz commented Jan 7, 2018

Also added MouseDragEnd1Pane so you don't have to press y after selecting with mouse.

Your current implementation in this PR is against the Linux convention. When we press y, we want the contents to be copied in the clipboard selection (xclip -selection clipboard):

yank_selection_default="clipboard"
yank_selection_option="@yank_selection"

elif command_exists "xclip"; then
local xclip_selection
xclip_selection="$(yank_selection)"
echo "xclip -selection $xclip_selection"

However selecting text with a mouse should only affect primary selection, never clipboard selection.

@kaliberr44
Copy link
Author

If I would remove the MouseDragEnd1Pane would this PR with default yank action be acceptable?

@maximbaz
Copy link
Contributor

maximbaz commented Jan 8, 2018

I have one more suggestion - set the default value of yank_action_default to copy-pipe-and-cancel instead of copy-pipe, because it seems right now you are changing the default behavior for every other user and I would recommend avoiding that.

I'm not an official maintainer of this project, but besides these two comments it seems OK to me 👍

@kaliberr44
Copy link
Author

I removed MouseDragEnd1Pane and set yank_action_default to copy-pipe-and-cancel

Copy link
Contributor

@maximbaz maximbaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks!

@maximbaz
Copy link
Contributor

maximbaz commented Feb 4, 2018

/cc @docwhat, you wanted to see a PR that fixes #40 🙂

@offero
Copy link

offero commented Feb 4, 2018

This will make life much better. Please merge soon!

@mcanfield
Copy link

@kaliberr44
The stack exchange answer How to successfully copy and paste with a mouse from tmux uses the MouseDragEnd1Pane that you proposed. I ended up modifying it to use pbcopy:

# Enable mouse mode
set -g mouse on
bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'select-pane -t=; copy-mode -e; send-keys -M'"
bind -n WheelDownPane select-pane -t= \; send-keys -M
bind -n C-WheelUpPane select-pane -t= \; copy-mode -e \; send-keys -M
bind -T copy-mode-vi    C-WheelUpPane   send-keys -X halfpage-up
bind -T copy-mode-vi    C-WheelDownPane send-keys -X halfpage-down

# To copy, left click and drag to highlight text
# once you release left click highlighted text will disappear and will automatically be available in clibboard
# Use vim keybindings in copy mode
setw -g mode-keys vi

# Update default binding of `Enter` to also use copy-pipe
unbind -T copy-mode-vi Enter
bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "reattach-to-user-namespace pbcopy"
bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "reattach-to-user-namespace pbcopy"

Perhaps you could repackage what you did coupled with this as a tmux-yank option flag. In any case, on macOS this works.

@yevhen-m
Copy link

What's the status of this PR? I guess lots of yank users are waiting for it to be merged.

@docwhat docwhat merged commit e8a03cf into tmux-plugins:master Mar 18, 2018
@yevhen-m
Copy link

I've tried to set

# tmux-yank settings
set -g @yank_action 'copy-pipe'

But I still get kicked out from copy mode after I press y or release mouse selection. What am I doing wrong?

@maximbaz
Copy link
Contributor

Have you restarted tmux? It worked for me.

@yevhen-m
Copy link

yevhen-m commented Mar 19, 2018

@maximbaz what os/terminal/tmux do you use?
Mine:

macos 10.13.3 
Iterm2 Build 3.1.6beta4
tmux/HEAD-06684c9

@maximbaz
Copy link
Contributor

maximbaz commented Mar 19, 2018

Try to reproduce also without using a mouse, enter copy mode, scroll up, select something and press y.

As for preserving the scroll after mouse selection, I have this in my .tmux.conf:

# Preserve mouse selection and scroll position after mouse drag
unbind -T copy-mode-vi MouseDragEnd1Pane

Full config for reference: https://github.com/maximbaz/dotfiles/blob/master/.tmux.conf

Note, I'm not using set -g @yank_action 'copy-pipe', but when I tested I placed it after line 118.

Arch Linux 4.15.10
tmux 2.6
alacritty terminal, latest master

@yevhen-m
Copy link

Well, it kind of works when I use keyboard only.
When I select something and hit y, selection is still there, text gets copied and I stay in copy-mode. Do you have the same behavior?

Also, your unbind line helped, now I can select text with mouse as well.

@yevhen-m
Copy link

I hoped that y would clear my selection but still leave my in copy mode and cursor at the same place. Can this be achieved somehow?

@maximbaz
Copy link
Contributor

Yes, that's exactly how it looks for me - selection stays and you are not scrolled back to the bottom.

I guess it has to be a combination of copy-pipe and clear-selection, but I'm not sure what's the proper syntax to combine these...

@yevhen-m
Copy link

@maximbaz thanks for help.
@kaliberr44 thanks for your PR.

I consider clearing selection and staying in copy mode very cool, so if anyone knows how to achieve this, please let us know.

@yevhen-m
Copy link

@maximbaz I've managed to bind keys like this:

bind-key -T copy-mode y send-keys -X copy-pipe "reattach-to-user-namespace pbcopy" \; send-keys -X clear-selection
bind-key -T copy-mode Y send-keys -X copy-pipe-and-cancel "tmux paste-buffer"
bind-key -T copy-mode-vi y send-keys -X copy-pipe "reattach-to-user-namespace pbcopy" \; send-keys -X clear-selection
bind-key -T copy-mode-vi Y send-keys -X copy-pipe-and-cancel "tmux paste-buffer"
unbind   -T copy-mode MouseDragEnd1Pane
unbind   -T copy-mode-vi MouseDragEnd1Pane

I guess reattach-to-user-namespace pbcopy should be changed for other systems. Frankly speaking I don't need tmux-yank anymore cause I can't see any reasons to keep it my my tmux.conf any longer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants