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 2 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
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"
Copy link
Contributor

Choose a reason for hiding this comment

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

Change that to local mouse="${1:-false}" to preserve previous callers.

# 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