-
Notifications
You must be signed in to change notification settings - Fork 0
/
tmux-click-copy.tmux
executable file
·63 lines (49 loc) · 2.2 KB
/
tmux-click-copy.tmux
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env bash
TCC_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
TCC_BIN="$TCC_PATH/scripts/tmux_click_copy.sh"
source "$TCC_PATH/scripts/helpers.sh"
TCC_DEFAULT_TIMEOUT="0.5"
TIMEOUT=$( get_tmux_option "@tcc_timeout" "$TCC_DEFAULT_TIMEOUT" )
TCC_DEFAULT_LONG_TIMEOUT="0.7"
LONG_TIMEOUT=$( get_tmux_option "@tcc_long_timeout" "$TCC_DEFAULT_LONG_TIMEOUT" )
TCC_AUTOBIND=true
AUTOBIND=$( get_tmux_option "@tcc_autobind" "$TCC_AUTOBIND" )
TCC_COMMAND="${TCC_BIN} #{pane_id} #{selection_start_x} #{selection_start_y} #{selection_end_x} #{selection_end_y} ${TIMEOUT} > /dev/null"
TCC_COMMAND_TRIPLE="${TCC_BIN} #{pane_id} #{selection_start_x} #{selection_start_y} #{selection_end_x} #{selection_end_y} ${LONG_TIMEOUT} > /dev/null"
# keep an option with the shell command so the user can bind it where they prefer
tmux set-option -g @TCC_COMMAND ${TCC_COMMAND}
tmux set-option -g @TCC_COMMAND_TRIPLE ${TCC_COMMAND_TRIPLE}
# if autobind is NOT true, exit now without binding anything
if ! [[ "$AUTOBIND" = true ]]; then
exit 0
fi
# Double & Triple click taken and modified from ideasman dotfiles with an async timer
# https://gitlab.com/ideasman42/dotfiles
# Double LMB Select & Copy (Word)
tmux bind-key -T copy-mode DoubleClick1Pane \
select-pane \\\; \
send-keys -X select-word \\\; \
send-keys -X copy-selection-no-clear \\\; \
run-shell -b "${TCC_COMMAND}"
tmux bind-key -T root DoubleClick1Pane \
select-pane -t = \\\; \
if-shell -F "#{||:#{pane_in_mode},#{mouse_any_flag}}" \
"send-keys -M" \
"copy-mode -H ; \
send-keys -X select-word ; \
send-keys -X copy-selection-no-clear ; \
run-shell -b \"${TCC_COMMAND}\" "
# Triple LMB Select & Copy (Line)
tmux bind-key -T copy-mode TripleClick1Pane \
select-pane \\\; \
send-keys -X select-line \\\; \
send-keys -X copy-selection-no-clear \\\; \
run-shell -b "${TCC_COMMAND_TRIPLE}"
tmux bind-key -n TripleClick1Pane \
select-pane -t = \\\; \
if-shell -F "#{||:#{pane_in_mode},#{mouse_any_flag}}" \
"send-keys -M" \
"copy-mode -H ; \
send-keys -X select-line ; \
send-keys -X copy-selection-no-clear ; \
run-shell -b \"${TCC_COMMAND_TRIPLE}\" "