Skip to content

Commit 22c55ea

Browse files
author
Bruno Sutic
committed
Make sure the line copy feature works with vi and emacs copy mode
1 parent 4a15a81 commit 22c55ea

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

scripts/copy_line.sh

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
#!/usr/bin/env bash
22

33
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4+
TMUX_COPY_MODE=""
45

56
source "$CURRENT_DIR/key_binding_helpers.sh"
67

78
COPY_COMMAND="$*"
89

10+
# sets a TMUX_COPY_MODE that is used as a global variable
11+
get_tmux_copy_mode() {
12+
TMUX_COPY_MODE="$(tmux show-option -gwv mode-keys)"
13+
}
14+
915
go_to_the_beginning_of_current_line() {
1016
tmux send-key 'C-a'
1117
}
@@ -15,11 +21,23 @@ enter_tmux_copy_mode() {
1521
}
1622

1723
start_tmux_selection() {
18-
tmux send-key 'Space'
24+
if [ "$TMUX_COPY_MODE" == "vi" ]; then
25+
# vi copy mode
26+
tmux send-key 'Space'
27+
else
28+
# emacs copy mode
29+
tmux send-key 'C-Space'
30+
fi
1931
}
2032

2133
end_of_line_in_copy_mode() {
22-
tmux send-key '$'
34+
if [ "$TMUX_COPY_MODE" == "vi" ]; then
35+
# vi copy mode
36+
tmux send-key '$'
37+
else
38+
# emacs copy mode
39+
tmux send-key 'C-e'
40+
fi
2341
}
2442

2543
yank_to_clipboard() {
@@ -45,6 +63,7 @@ yank_current_line() {
4563
}
4664

4765
main() {
66+
get_tmux_copy_mode
4867
yank_current_line
4968
}
5069
main

0 commit comments

Comments
 (0)