Skip to content

Commit ea13a18

Browse files
author
Bruno Sutic
committed
Bugfix: copy line binding never yanks newlines
This addresses a tmux/bash issue that occurs for commands with multiple lines. When 'C-e' is pressed in a command, this confuses tmux so newlines are yanked in copy-mode. When a user wants to line-yank multiple-line command he is better off when newlines aren't yanked. This commit reliably enables this. Fixes #13
1 parent 2fa5010 commit ea13a18

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
- fix bug when yank-line is used in the last line in buffer. New 'solution' is
88
implemented for copying multiple lines.
99
- code cleanup
10+
- yank-line never yanks 'newline' char for multiple-line commands in shell (this
11+
is actually tmux/bash bug).
1012

1113
### v0.0.2, Jun 25, 2014
1214

scripts/copy_line.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ end_of_line_in_copy_mode() {
6363
}
6464

6565
yank_to_clipboard() {
66-
tmux send-key "$(yank_key)"
66+
tmux send-key "$(yank_wo_newline_key)"
6767
}
6868

6969
go_to_the_end_of_current_line() {

scripts/key_binding_helpers.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ put_option="@copy_mode_put"
1010
yank_put_default="M-y"
1111
yank_put_option="@copy_mode_yank_put"
1212

13+
yank_wo_newline_default="!"
14+
yank_wo_newline_option="@copy_mode_yank_wo_newline"
15+
1316
# helper functions
1417
get_tmux_option() {
1518
local option="$1"
@@ -38,6 +41,10 @@ yank_put_key() {
3841
echo "$(get_tmux_option "$yank_put_option" "$yank_put_default")"
3942
}
4043

44+
yank_wo_newline_key() {
45+
echo "$(get_tmux_option "$yank_wo_newline_option" "$yank_wo_newline_default")"
46+
}
47+
4148
# Ensures a message is displayed for 5 seconds in tmux prompt.
4249
# Does not override the 'display-time' tmux option.
4350
display_message() {

yank.tmux

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ clipboard_copy_command() {
1818
fi
1919
}
2020

21+
clipboard_copy_without_newline_command() {
22+
local copy_command="$1"
23+
echo "tr -d '\n' | $copy_command"
24+
}
25+
2126
set_error_bindings() {
2227
local key_bindings="$(yank_key) $(put_key) $(yank_put_key)"
2328
local key
@@ -35,15 +40,20 @@ error_handling_if_command_not_present() {
3540
fi
3641
}
3742

43+
# `yank_without_newline` binding isn't intended to be used by the user. It is
44+
# a helper for `copy_line` command.
3845
set_copy_mode_bindings() {
3946
local copy_command="$1"
47+
local copy_wo_newline_command="$(clipboard_copy_without_newline_command "$copy_command")"
4048
tmux bind-key -t vi-copy "$(yank_key)" copy-pipe "$copy_command"
4149
tmux bind-key -t vi-copy "$(put_key)" copy-pipe "tmux paste-buffer"
4250
tmux bind-key -t vi-copy "$(yank_put_key)" copy-pipe "$copy_command; tmux paste-buffer"
51+
tmux bind-key -t vi-copy "$(yank_wo_newline_key)" copy-pipe "$copy_wo_newline_command"
4352

4453
tmux bind-key -t emacs-copy "$(yank_key)" copy-pipe "$copy_command"
4554
tmux bind-key -t emacs-copy "$(put_key)" copy-pipe "tmux paste-buffer"
4655
tmux bind-key -t emacs-copy "$(yank_put_key)" copy-pipe "$copy_command; tmux paste-buffer"
56+
tmux bind-key -t emacs-copy "$(yank_wo_newline_key)" copy-pipe "$copy_wo_newline_command"
4757
}
4858

4959
set_copy_line_bindings() {

0 commit comments

Comments
 (0)