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

Add yank on MouseDragEnd1Pane #109

Merged
merged 5 commits into from
Dec 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Change Log
[master]
--------

### Added

- Mouse support, controlled by `yank_with_mouse` and `yank_selection_mouse`
(@keidax)

[v2.3.0] 2018-02-01
-------------------

Expand Down
43 changes: 39 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,48 @@ You can change this by setting `@yank_selection`:
set -g @yank_selection 'primary' # or 'secondary' or 'clipboard'
```

With mouse support turned on (see below) the default clipboard for mouse
selections is `primary`.

You can change this by setting `@yank_selection_mouse`:

``` tmux
# ~/.tmux.conf

set -g @yank_selection_mouse 'clipboard' # or 'primary' or 'secondary'
```

### Controlling Yank Behavior

By default, `tmux-yank` will exit copy mode after yanking text. If you wish to
remain in copy mode, you can set `@yank_action`:

``` tmux
# ~/.tmux.conf

set -g @yank_action 'copy-pipe' # or 'copy-pipe-and-cancel' for the default
```

### Mouse Support

When making a selection using `tmux` with `mode-mouse on` or
`mode-mouse copy-mode`, you cannot rely on the default 'release mouse after
selection to copy' behavior.
`tmux-yank` has mouse support enabled by default. It will only work if `tmux`'s
built-in mouse support is also enabled (with `mouse on` since `tmux` 2.1, or
`mode-mouse on` in older versions).

To yank with the mouse, click and drag with the primary button to begin
selection, and release to yank.

If you would prefer to disable this behavior, or provide your own bindings for
the `MouseDragEnd1Pane` event, you can do so with:

``` tmux
# ~/.tmux.conf

set -g @yank_with_mouse off # or 'on'
```

Instead, press <kbd>y</kbd> before releasing mouse.
If you want to remain in copy mode after making a mouse selection, set
`@yank_action` as described above.

### vi mode support

Expand Down
27 changes: 25 additions & 2 deletions scripts/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ yank_wo_newline_option="@copy_mode_yank_wo_newline"
yank_selection_default="clipboard"
yank_selection_option="@yank_selection"

yank_selection_mouse_default="primary"
yank_selection_mouse_option="@yank_selection_mouse"

yank_with_mouse_default="on"
yank_with_mouse_option="@yank_with_mouse"

Copy link
Contributor

Choose a reason for hiding this comment

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

I would appreciate it if you could add a description of these to the README.md.

yank_action_default="copy-pipe-and-cancel"
yank_action_option="@yank_action"

Expand Down Expand Up @@ -74,6 +80,14 @@ yank_selection() {
get_tmux_option "$yank_selection_option" "$yank_selection_default"
}

yank_selection_mouse() {
get_tmux_option "$yank_selection_mouse_option" "$yank_selection_mouse_default"
}

yank_with_mouse() {
get_tmux_option "$yank_with_mouse_option" "$yank_with_mouse_default"
}

yank_action() {
get_tmux_option "$yank_action_option" "$yank_action_default"
}
Expand Down Expand Up @@ -121,6 +135,7 @@ command_exists() {
}

clipboard_copy_command() {
local mouse="${1:-false}"
# installing reattach-to-user-namespace is recommended on OS X
if [ -n "$(override_copy_command)" ]; then
override_copy_command
Expand All @@ -134,11 +149,19 @@ clipboard_copy_command() {
echo "clip.exe"
elif command_exists "xclip"; then
local xclip_selection
xclip_selection="$(yank_selection)"
if [[ "$mouse" == "true" ]]; then
xclip_selection="$(yank_selection_mouse)"
else
xclip_selection="$(yank_selection)"
fi
echo "xclip -selection $xclip_selection"
elif command_exists "xsel"; then
local xsel_selection
xsel_selection="$(yank_selection)"
if [[ "$mouse" == "true" ]]; then
xsel_selection="$(yank_selection_mouse)"
else
xsel_selection="$(yank_selection)"
fi
echo "xsel -i --$xsel_selection"
elif command_exists "putclip"; then # cygwin clipboard command
echo "putclip"
Expand Down
14 changes: 14 additions & 0 deletions yank.tmux
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,40 @@ set_copy_mode_bindings() {
local copy_command="$1"
local copy_wo_newline_command
copy_wo_newline_command="$(clipboard_copy_without_newline_command "$copy_command")"
local copy_command_mouse
copy_command_mouse="$(clipboard_copy_command "true")"
if tmux_is_at_least 2.4; then
tmux bind-key -T copy-mode-vi "$(yank_key)" send-keys -X "$(yank_action)" "$copy_command"
tmux bind-key -T copy-mode-vi "$(put_key)" send-keys -X copy-pipe-and-cancel "tmux paste-buffer"
tmux bind-key -T copy-mode-vi "$(yank_put_key)" send-keys -X copy-pipe-and-cancel "$copy_command; tmux paste-buffer"
tmux bind-key -T copy-mode-vi "$(yank_wo_newline_key)" send-keys -X "$(yank_action)" "$copy_wo_newline_command"
if [[ "$(yank_with_mouse)" == "on" ]]; then
tmux bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X "$(yank_action)" "$copy_command_mouse"
fi

tmux bind-key -T copy-mode "$(yank_key)" send-keys -X "$(yank_action)" "$copy_command"
tmux bind-key -T copy-mode "$(put_key)" send-keys -X copy-pipe-and-cancel "tmux paste-buffer"
tmux bind-key -T copy-mode "$(yank_put_key)" send-keys -X copy-pipe-and-cancel "$copy_command; tmux paste-buffer"
tmux bind-key -T copy-mode "$(yank_wo_newline_key)" send-keys -X "$(yank_action)" "$copy_wo_newline_command"
if [[ "$(yank_with_mouse)" == "on" ]]; then
tmux bind-key -T copy-mode MouseDragEnd1Pane send-keys -X "$(yank_action)" "$copy_command_mouse"
fi
else
tmux bind-key -t vi-copy "$(yank_key)" copy-pipe "$copy_command"
tmux bind-key -t vi-copy "$(put_key)" copy-pipe "tmux paste-buffer"
tmux bind-key -t vi-copy "$(yank_put_key)" copy-pipe "$copy_command; tmux paste-buffer"
tmux bind-key -t vi-copy "$(yank_wo_newline_key)" copy-pipe "$copy_wo_newline_command"
if [[ "$(yank_with_mouse)" == "on" ]]; then
tmux bind-key -t vi-copy MouseDragEnd1Pane copy-pipe "$copy_command_mouse"
fi

tmux bind-key -t emacs-copy "$(yank_key)" copy-pipe "$copy_command"
tmux bind-key -t emacs-copy "$(put_key)" copy-pipe "tmux paste-buffer"
tmux bind-key -t emacs-copy "$(yank_put_key)" copy-pipe "$copy_command; tmux paste-buffer"
tmux bind-key -t emacs-copy "$(yank_wo_newline_key)" copy-pipe "$copy_wo_newline_command"
if [[ "$(yank_with_mouse)" == "on" ]]; then
tmux bind-key -t emacs-copy MouseDragEnd1Pane copy-pipe "$copy_command_mouse"
fi
fi
}

Expand Down