From 23a3336c0d2c65306a9cb1aeb386bbe24f8b38a5 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 20 May 2018 02:38:04 -0400 Subject: allow using either the primary or clipboard selections on linux --- bin/tmux-clipboard | 22 ++++++++++++++++++---- tmux.conf | 10 ++++++---- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/bin/tmux-clipboard b/bin/tmux-clipboard index 1e10fcf..7f939e1 100755 --- a/bin/tmux-clipboard +++ b/bin/tmux-clipboard @@ -20,13 +20,20 @@ END { $fifo_file->remove } mkfifo("$fifo_file", 0700); if ($ARGV[0] eq 'copy') { + my $selection = $ARGV[1] || 'primary'; + if (fork) { close STDIN; close STDOUT; close STDERR; - open my $clipboard, '|-', COPY_CMD - or die "can't copy from clipboard using ${\COPY_CMD}: $!"; + my $copy_cmd = COPY_CMD; + if ($Config{osname} eq 'linux') { + $copy_cmd .= " -selection $selection"; + } + + open my $clipboard, '|-', $copy_cmd + or die "can't copy from clipboard using $copy_cmd: $!"; $clipboard->print($fifo_file->slurp); $clipboard->close; } @@ -35,13 +42,20 @@ if ($ARGV[0] eq 'copy') { } } elsif ($ARGV[0] eq 'paste') { + my $selection = $ARGV[1] || 'primary'; + if (fork) { close STDIN; close STDOUT; close STDERR; - open my $clipboard, '-|', PASTE_CMD - or die "can't paste from clipboard using ${\PASTE_CMD}: $!"; + my $paste_cmd = PASTE_CMD; + if ($Config{osname} eq 'linux') { + $paste_cmd .= " -selection $selection"; + } + + open my $clipboard, '-|', $paste_cmd + or die "can't paste from clipboard using $paste_cmd: $!"; my $contents = do { local $/; <$clipboard> }; $clipboard->close; $fifo_file->spew(iomode => 'a', $contents); diff --git a/tmux.conf b/tmux.conf index a9ae155..4ef6dea 100644 --- a/tmux.conf +++ b/tmux.conf @@ -39,13 +39,15 @@ bind { copy-mode bind Enter run 'tmux capture-pane -p | perl -MURL::Search -E"say for URL::Search::extract_urls(do { local \$/; <> })" | tail -n1 | xargs xdg-open' bind -T copy-mode-vi v send-keys -X begin-selection -bind -T copy-mode-vi y send-keys -X copy-selection-and-cancel bind -T copy-mode-vi ) send-keys -X start-of-line bind -T copy-mode-vi _ send-keys -X back-to-indentation -bind -T copy-mode-vi ^C run "tmux send-keys -X copy-selection-and-cancel; tmux-clipboard copy" -bind ^C run "tmux-clipboard copy" -bind ^V run "tmux-clipboard paste" +bind -T copy-mode-vi y run "tmux send-keys -X copy-selection-and-cancel; tmux-clipboard copy primary" +bind -T copy-mode-vi ^C run "tmux send-keys -X copy-selection-and-cancel; tmux-clipboard copy clipboard" +bind y run "tmux-clipboard copy primary" +bind ^C run "tmux-clipboard copy clipboard" +bind IC run "tmux-clipboard paste primary" +bind ^V run "tmux-clipboard paste clipboard" unbind ^B -- cgit v1.2.3-54-g00ecf