Discussion:
interpolate #{pane_tty} into copy-pipe
Suraj N. Kurapati
2014-11-05 01:41:09 UTC
Permalink
Hello,

I'm trying to use copy-pipe with my yank[1] script to copy the
selection to my system clipboard via the OSC 52 escape sequence.
But in order for this to work, the escape sequence needs to be
written *directly* to the terminal device that has tmux attached.

I tried the following copy-mode key bindings, but nothing worked:

bind-key -t vi-copy y copy-pipe 'yank'
bind-key -t vi-copy y copy-pipe 'yank > /dev/tty'
bind-key -t vi-copy y copy-pipe 'yank > #{pane_tty}'
bind-key -t vi-copy y copy-pipe 'tmux run-shell "yank > #{pane_tty}"'

In contrast, writing to #{pane_tty} works in normal key bindings:

# transfer most-recently copied text to attached terminal with yank:
bind-key -n M-y run-shell 'tmux save-buffer - | yank > #{pane_tty}'

# transfer previously copied text (chosen from a menu) to attached terminal:
bind-key -n M-Y choose-buffer 'run-shell "tmux save-buffer -b \"%%\" - | yank > #{pane_tty}"'

How can I interpolate the correct #{pane_tty} value into copy-pipe?

Thanks for your consideration.

[1]: https://github.com/sunaku/home/blob/master/bin/yank

------------------------------------------------------------------------------
Nicholas Marriott
2014-11-05 22:57:14 UTC
Permalink
Try this please (although if your terminal supports OSC 52 you could
just put Ms in terminal-overrides and turn on set-clipboard).

diff --git a/window-copy.c b/window-copy.c
index 542c28a..965583a 100644
--- a/window-copy.c
+++ b/window-copy.c
@@ -1480,18 +1480,28 @@ void
window_copy_copy_pipe(struct window_pane *wp, struct session *sess,
const char *bufname, const char *arg)
{
- void *buf;
- size_t len;
- struct job *job;
-
+ void *buf;
+ size_t len;
+ struct job *job;
+ struct format_tree *ft;
+ char *expanded;

buf = window_copy_get_selection(wp, &len);
if (buf == NULL)
return;

- job = job_run(arg, sess, NULL, NULL, NULL);
+ ft = format_create();
+ format_window_pane(ft, wp);
+ if (sess != NULL)
+ format_session(ft, sess);
+ expanded = format_expand(ft, arg);
+
+ job = job_run(expanded, sess, NULL, NULL, NULL);
bufferevent_write(job->event, buf, len);

+ free(expanded);
+ format_free(ft);
+
window_copy_copy_buffer(wp, bufname, buf, len);
}
Post by Suraj N. Kurapati
Hello,
I'm trying to use copy-pipe with my yank[1] script to copy the
selection to my system clipboard via the OSC 52 escape sequence.
But in order for this to work, the escape sequence needs to be
written *directly* to the terminal device that has tmux attached.
bind-key -t vi-copy y copy-pipe 'yank'
bind-key -t vi-copy y copy-pipe 'yank > /dev/tty'
bind-key -t vi-copy y copy-pipe 'yank > #{pane_tty}'
bind-key -t vi-copy y copy-pipe 'tmux run-shell "yank > #{pane_tty}"'
bind-key -n M-y run-shell 'tmux save-buffer - | yank > #{pane_tty}'
bind-key -n M-Y choose-buffer 'run-shell "tmux save-buffer -b \"%%\" - | yank > #{pane_tty}"'
How can I interpolate the correct #{pane_tty} value into copy-pipe?
Thanks for your consideration.
[1]: https://github.com/sunaku/home/blob/master/bin/yank
------------------------------------------------------------------------------
_______________________________________________
tmux-users mailing list
https://lists.sourceforge.net/lists/listinfo/tmux-users
------------------------------------------------------------------------------
Suraj N. Kurapati
2014-11-09 01:50:32 UTC
Permalink
Post by Nicholas Marriott
Try this please
Thanks! The following configuration now works due to this patch:

bind-key -t vi-copy y copy-pipe 'yank > #{pane_tty}'

I would request you to promote this patch into the tmux codebase.
Post by Nicholas Marriott
(although if your terminal supports OSC 52 you could
just put Ms in terminal-overrides and turn on set-clipboard).
Thanks for the tip, that's very handy. It doesn't handle my needs
though because it copies to the primary selection rather than the
clipboard selection, which is troublesome for me because hitting
mouse3 (middle click) on a laptop touchpad is largely hit-or-miss.

Thanks for your consideration.

------------------------------------------------------------------------------
Ailin Nemui
2014-11-09 08:40:57 UTC
Permalink
Post by Suraj N. Kurapati
Thanks for the tip, that's very handy. It doesn't handle my needs
though because it copies to the primary selection rather than the
clipboard selection, which is troublesome for me because hitting
mouse3 (middle click) on a laptop touchpad is largely hit-or-miss.
On most host Terminals the target of clipboard operation is configurable, see eg man xterm


------------------------------------------------------------------------------
Nicholas Marriott
2014-11-09 14:56:25 UTC
Permalink
You can configure xterm so OSC 52 defaults to clipboard, or set Ms so
that tmux sends it to clipboard. Probably something like Ms=\E]52;c;%p2%s\007
Post by Suraj N. Kurapati
Post by Nicholas Marriott
Try this please
bind-key -t vi-copy y copy-pipe 'yank > #{pane_tty}'
I would request you to promote this patch into the tmux codebase.
Post by Nicholas Marriott
(although if your terminal supports OSC 52 you could
just put Ms in terminal-overrides and turn on set-clipboard).
Thanks for the tip, that's very handy. It doesn't handle my needs
though because it copies to the primary selection rather than the
clipboard selection, which is troublesome for me because hitting
mouse3 (middle click) on a laptop touchpad is largely hit-or-miss.
Thanks for your consideration.
------------------------------------------------------------------------------
Suraj N. Kurapati
2014-11-09 18:49:12 UTC
Permalink
Post by Nicholas Marriott
You can configure xterm so OSC 52 defaults to clipboard, or set Ms
so that tmux sends it to clipboard. Probably something like
Ms=\E]52;c;%p2%s\007
Thanks for the tip! I was able to use your suggestion successfully:

set-option -ga terminal-overrides ',xterm*:Ms=\E]52;c;%p2%s\007'

However, I would still request this patch to be promoted into the
tmux codebase because I sometimes use non-xterm terminals (hterm).

------------------------------------------------------------------------------
Nicholas Marriott
2014-11-09 18:53:22 UTC
Permalink
Patch is in openbsd now will be in SF next time it's synced up

-------- Original message --------
From: "Suraj N. Kurapati" <***@gmail.com>
Date: 09/11/2014 18:49 (GMT+00:00)
To: Nicholas Marriott <***@gmail.com>
Cc: tmux-***@lists.sourceforge.net
Subject: Re: interpolate #{pane_tty} into copy-pipe
Post by Nicholas Marriott
You can configure xterm so OSC 52 defaults to clipboard, or set Ms
so that tmux sends it to clipboard. Probably something like
Ms=\E]52;c;%p2%s\007
Thanks for the tip! I was able to use your suggestion successfully:

  set-option -ga terminal-overrides ',xterm*:Ms=\E]52;c;%p2%s\007'

However, I would still request this patch to be promoted into the
tmux codebase because I sometimes use non-xterm terminals (hterm).
Suraj N. Kurapati
2014-11-10 18:19:09 UTC
Permalink
Post by Nicholas Marriott
Patch is in openbsd now will be in SF next time it's synced up
Wonderful! Thanks for all of your help. Long live tmux! :)

------------------------------------------------------------------------------
Loading...