Skip to content

Commit

Permalink
Fix copy/paste to work seamlessly with the X clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy T. Braun committed Apr 15, 2016
1 parent e306c64 commit 167a85d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
28 changes: 28 additions & 0 deletions scripts/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ yank_wo_newline_option="@copy_mode_yank_wo_newline"
yank_selection_default="clipboard"
yank_selection_option="@yank_selection"

paste_selection_default="clipboard"
paste_selection_option="@paste_selection"

shell_mode_default="emacs"
shell_mode_option="@shell_mode"

Expand Down Expand Up @@ -65,6 +68,10 @@ yank_selection() {
echo "$(get_tmux_option "$yank_selection_option" "$yank_selection_default")"
}

paste_selection() {
echo "$(get_tmux_option "$paste_selection_option" "$paste_selection_default")"
}

shell_mode() {
echo "$(get_tmux_option "$shell_mode_option" "$shell_mode_default")"
}
Expand Down Expand Up @@ -122,3 +129,24 @@ clipboard_copy_command() {
echo "$(custom_copy_command)"
fi
}

clipboard_paste_command() {
# installing reattach-to-user-namespace is recommended on OS X
if command_exists "pbpaste"; then
if command_exists "reattach-to-user-namespace"; then
echo "reattach-to-user-namespace pbcopy"
else
echo "pbpaste"
fi
elif command_exists "xclip"; then
local xclip_selection="$(past_selection)"
echo "xclip -o -selection $xclip_selection"
elif command_exists "xsel"; then
local xsel_selection="$(paste_selection)"
echo "xsel -o --$xsel_selection"
elif command_exists "getclip"; then # cygwin clipboard command
echo "getclip"
elif [ -n "$(custom_paste_command)" ]; then
echo "$(custom_paste_command)"
fi
}
12 changes: 12 additions & 0 deletions scripts/paste_pane.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
HELPERS_DIR="$CURRENT_DIR"

source "$HELPERS_DIR/helpers.sh"

main() {
tmux send-keys -l "$($(clipboard_paste_command))"
}

main
12 changes: 8 additions & 4 deletions yank.tmux
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,24 @@ error_handling_if_command_not_present() {
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 "$(yank_key)" copy-pipe "$copy_command"
tmux bind-key -t vi-copy MouseDragEnd1Pane 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 "$(yank_key)" copy-pipe "$copy_command"
tmux bind-key -t emacs-copy MouseDragEnd1Pane 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"

tmux bind-key -T root MouseDown2Pane run-shell "$SCRIPTS_DIR/paste_pane.sh"
}

set_normal_bindings() {
tmux bind-key "$(yank_line_key)" run-shell -b "$SCRIPTS_DIR/copy_line.sh"
tmux bind-key "$(yank_pane_pwd_key)" run-shell -b "$SCRIPTS_DIR/copy_pane_pwd.sh"
tmux bind-key "$(yank_line_key)" run-shell "$SCRIPTS_DIR/copy_line.sh"
tmux bind-key "$(yank_pane_pwd_key)" run-shell "$SCRIPTS_DIR/copy_pane_pwd.sh"
}

main() {
Expand Down

0 comments on commit 167a85d

Please sign in to comment.