Skip to content

Commit d3a8735

Browse files
committed
Add mouse bindings and separate selection option
1 parent e8a03cf commit d3a8735

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

scripts/helpers.sh

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ yank_wo_newline_option="@copy_mode_yank_wo_newline"
2121
yank_selection_default="clipboard"
2222
yank_selection_option="@yank_selection"
2323

24+
yank_selection_mouse_default="primary"
25+
yank_selection_mouse_option="@yank_selection_mouse"
26+
2427
yank_action_default="copy-pipe-and-cancel"
2528
yank_action_option="@yank_action"
2629

@@ -74,6 +77,10 @@ yank_selection() {
7477
get_tmux_option "$yank_selection_option" "$yank_selection_default"
7578
}
7679

80+
yank_selection_mouse() {
81+
get_tmux_option "$yank_selection_mouse_option" "$yank_selection_mouse_default"
82+
}
83+
7784
yank_action() {
7885
get_tmux_option "$yank_action_option" "$yank_action_default"
7986
}
@@ -121,6 +128,7 @@ command_exists() {
121128
}
122129

123130
clipboard_copy_command() {
131+
local mouse="$1"
124132
# installing reattach-to-user-namespace is recommended on OS X
125133
if [ -n "$(override_copy_command)" ]; then
126134
override_copy_command
@@ -134,11 +142,19 @@ clipboard_copy_command() {
134142
echo "clip.exe"
135143
elif command_exists "xclip"; then
136144
local xclip_selection
137-
xclip_selection="$(yank_selection)"
145+
if [[ "$mouse" == "true" ]]; then
146+
xclip_selection="$(yank_selection_mouse)"
147+
else
148+
xclip_selection="$(yank_selection)"
149+
fi
138150
echo "xclip -selection $xclip_selection"
139151
elif command_exists "xsel"; then
140152
local xsel_selection
141-
xsel_selection="$(yank_selection)"
153+
if [[ "$mouse" == "true" ]]; then
154+
xsel_selection="$(yank_selection_mouse)"
155+
else
156+
xsel_selection="$(yank_selection)"
157+
fi
142158
echo "xsel -i --$xsel_selection"
143159
elif command_exists "putclip"; then # cygwin clipboard command
144160
echo "putclip"

yank.tmux

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,32 @@ set_copy_mode_bindings() {
4040
local copy_command="$1"
4141
local copy_wo_newline_command
4242
copy_wo_newline_command="$(clipboard_copy_without_newline_command "$copy_command")"
43+
local copy_command_mouse
44+
copy_command_mouse="$(clipboard_copy_command "true")"
4345
if tmux_is_at_least 2.4; then
4446
tmux bind-key -T copy-mode-vi "$(yank_key)" send-keys -X "$(yank_action)" "$copy_command"
4547
tmux bind-key -T copy-mode-vi "$(put_key)" send-keys -X copy-pipe-and-cancel "tmux paste-buffer"
4648
tmux bind-key -T copy-mode-vi "$(yank_put_key)" send-keys -X copy-pipe-and-cancel "$copy_command; tmux paste-buffer"
4749
tmux bind-key -T copy-mode-vi "$(yank_wo_newline_key)" send-keys -X "$(yank_action)" "$copy_wo_newline_command"
50+
tmux bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X "$(yank_action)" "$copy_command_mouse"
4851

4952
tmux bind-key -T copy-mode "$(yank_key)" send-keys -X "$(yank_action)" "$copy_command"
5053
tmux bind-key -T copy-mode "$(put_key)" send-keys -X copy-pipe-and-cancel "tmux paste-buffer"
5154
tmux bind-key -T copy-mode "$(yank_put_key)" send-keys -X copy-pipe-and-cancel "$copy_command; tmux paste-buffer"
5255
tmux bind-key -T copy-mode "$(yank_wo_newline_key)" send-keys -X "$(yank_action)" "$copy_wo_newline_command"
56+
tmux bind-key -T copy-mode MouseDragEnd1Pane send-keys -X "$(yank_action)" "$copy_command_mouse"
5357
else
5458
tmux bind-key -t vi-copy "$(yank_key)" copy-pipe "$copy_command"
5559
tmux bind-key -t vi-copy "$(put_key)" copy-pipe "tmux paste-buffer"
5660
tmux bind-key -t vi-copy "$(yank_put_key)" copy-pipe "$copy_command; tmux paste-buffer"
5761
tmux bind-key -t vi-copy "$(yank_wo_newline_key)" copy-pipe "$copy_wo_newline_command"
62+
tmux bind-key -t vi-copy MouseDragEnd1Pane copy-pipe "$copy_command_mouse"
5863

5964
tmux bind-key -t emacs-copy "$(yank_key)" copy-pipe "$copy_command"
6065
tmux bind-key -t emacs-copy "$(put_key)" copy-pipe "tmux paste-buffer"
6166
tmux bind-key -t emacs-copy "$(yank_put_key)" copy-pipe "$copy_command; tmux paste-buffer"
6267
tmux bind-key -t emacs-copy "$(yank_wo_newline_key)" copy-pipe "$copy_wo_newline_command"
68+
tmux bind-key -t emacs-copy MouseDragEnd1Pane copy-pipe "$copy_command_mouse"
6369
fi
6470
}
6571

0 commit comments

Comments
 (0)