Skip to content

Commit

Permalink
Bugfix: copy line binding never yanks newlines
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Bruno Sutic committed Jun 29, 2014
1 parent 2fa5010 commit ea13a18
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
- fix bug when yank-line is used in the last line in buffer. New 'solution' is
implemented for copying multiple lines.
- code cleanup
- yank-line never yanks 'newline' char for multiple-line commands in shell (this
is actually tmux/bash bug).

### v0.0.2, Jun 25, 2014

Expand Down
2 changes: 1 addition & 1 deletion scripts/copy_line.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ end_of_line_in_copy_mode() {
}

yank_to_clipboard() {
tmux send-key "$(yank_key)"
tmux send-key "$(yank_wo_newline_key)"
}

go_to_the_end_of_current_line() {
Expand Down
7 changes: 7 additions & 0 deletions scripts/key_binding_helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ put_option="@copy_mode_put"
yank_put_default="M-y"
yank_put_option="@copy_mode_yank_put"

yank_wo_newline_default="!"
yank_wo_newline_option="@copy_mode_yank_wo_newline"

# helper functions
get_tmux_option() {
local option="$1"
Expand Down Expand Up @@ -38,6 +41,10 @@ yank_put_key() {
echo "$(get_tmux_option "$yank_put_option" "$yank_put_default")"
}

yank_wo_newline_key() {
echo "$(get_tmux_option "$yank_wo_newline_option" "$yank_wo_newline_default")"
}

# Ensures a message is displayed for 5 seconds in tmux prompt.
# Does not override the 'display-time' tmux option.
display_message() {
Expand Down
10 changes: 10 additions & 0 deletions yank.tmux
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ clipboard_copy_command() {
fi
}

clipboard_copy_without_newline_command() {
local copy_command="$1"
echo "tr -d '\n' | $copy_command"
}

set_error_bindings() {
local key_bindings="$(yank_key) $(put_key) $(yank_put_key)"
local key
Expand All @@ -35,15 +40,20 @@ error_handling_if_command_not_present() {
fi
}

# `yank_without_newline` binding isn't intended to be used by the user. It is
# a helper for `copy_line` command.
set_copy_mode_bindings() {
local copy_command="$1"
local copy_wo_newline_command="$(clipboard_copy_without_newline_command "$copy_command")"
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"

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"
}

set_copy_line_bindings() {
Expand Down

0 comments on commit ea13a18

Please sign in to comment.