Discussion:
yank buffer to clipboard, like copy-mode does
Suraj N. Kurapati
2014-12-12 19:27:14 UTC
Permalink
Hello,

I have tmux configured to copy text I select with keyboard or mouse
(in copy-mode) to my system clipboard:

# yank to system clipboard rather than primary selection
# http://invisible-island.net/xterm/terminfo-contents.html#tic-xterm_tmux
set-option -ga terminal-overrides ',xterm*:Ms=\E]52;c;%p2%s\007'

However, the `setb` and `loadb` commands don't behave the same way:
they modify tmux's internal buffers without touching the clipboard.

Would it be possible to make `setb` and `loadb` copy to clipboard?
Alternatively, could we have a new `yankb` command that does this?

yank-buffer [-a] [-b buffer-name]
(alias: yankb)
Yanks the contents of the specified buffer to clipboard.

Thanks for your consideration.
Suraj N. Kurapati
2014-12-14 18:38:48 UTC
Permalink
Post by Suraj N. Kurapati
Would it be possible to make `setb` and `loadb` copy to clipboard?
Attached is a rudimentary patch that enhances the `setb` and `loadb`
commands to copy to the clipboard, just like the `copy-mode` command.

Please consider adding this functionality to tmux itself; thank you!
Nicholas Marriott
2014-12-15 09:20:12 UTC
Permalink
Not sure about this, there are already tools to do this like xsel and
xclip, what's the use case for tmux doing it too?
Post by Suraj N. Kurapati
Post by Suraj N. Kurapati
Would it be possible to make `setb` and `loadb` copy to clipboard?
Attached is a rudimentary patch that enhances the `setb` and `loadb`
commands to copy to the clipboard, just like the `copy-mode` command.
Please consider adding this functionality to tmux itself; thank you!
Post by Suraj N. Kurapati
From 93eea3cf4c1867ab473cfaebe01517292a5f0180 Mon Sep 17 00:00:00 2001
Date: Sun, 14 Dec 2014 10:30:36 -0800
Subject: [PATCH] ensure setb and loadb commands copy to clipboard
This is an ugly implementation, meant only as a proof-of-concept.
---
cmd-load-buffer.c | 2 ++
cmd-set-buffer.c | 2 ++
paste.c | 17 +++++++++++++++++
tmux.h | 1 +
4 files changed, 22 insertions(+)
diff --git a/cmd-load-buffer.c b/cmd-load-buffer.c
index 785a701..d361c59 100644
--- a/cmd-load-buffer.c
+++ b/cmd-load-buffer.c
@@ -152,6 +152,8 @@ cmd_load_buffer_callback(struct client *c, int closed, void *data)
free(cause);
}
+ paste_set_clipboard(pdata, psize, c->cmdq);
+
cmdq_continue(c->cmdq);
}
diff --git a/cmd-set-buffer.c b/cmd-set-buffer.c
index 0ec362b..1f5d6bf 100644
--- a/cmd-set-buffer.c
+++ b/cmd-set-buffer.c
@@ -114,5 +114,7 @@ cmd_set_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
return (CMD_RETURN_ERROR);
}
+ paste_set_clipboard(pdata, psize, cmdq);
+
return (CMD_RETURN_NORMAL);
}
diff --git a/paste.c b/paste.c
index 998b975..06f962c 100644
--- a/paste.c
+++ b/paste.c
@@ -219,6 +219,23 @@ paste_rename(const char *oldname, const char *newname, char **cause)
return (0);
}
+void
+paste_set_clipboard(char *buf, size_t len, struct cmd_q *cmdq)
+{
+ struct screen_write_ctx ctx;
+ struct window_pane *wp;
+
+ if (!options_get_number(&global_options, "set-clipboard"))
+ return;
+
+ if (cmd_find_pane(cmdq, NULL, NULL, &wp) == NULL)
+ return;
+
+ screen_write_start(&ctx, wp, NULL);
+ screen_write_setselection(&ctx, buf, len);
+ screen_write_stop(&ctx);
+}
+
/*
* Add or replace an item in the store. Note that the caller is responsible for
* allocating data.
diff --git a/tmux.h b/tmux.h
index 61f2ca7..2189142 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1688,6 +1688,7 @@ int paste_free_name(const char *);
void paste_add(char *, size_t);
int paste_rename(const char *, const char *, char **);
int paste_set(char *, size_t, const char *, char **);
+void paste_set_clipboard(char *, size_t, struct cmd_q *);
char *paste_make_sample(struct paste_buffer *, int);
void paste_send_pane(struct paste_buffer *, struct window_pane *,
const char *, int);
--
2.1.0
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
tmux-users mailing list
https://lists.sourceforge.net/lists/listinfo/tmux-users
Nicholas Marriott
2014-12-15 19:37:57 UTC
Permalink
Ok. I think I would prefer a flag (maybe to paste-buffer?) to send an
existing buffer to the clipboard, rather than changing setb/loadb.

You would still be able to copy a buffer from loadb/setb with something
like:

loadb -btmp /my/file; pasteb -Xbtmp; deleteb -btmp
Post by Nicholas Marriott
Not sure about this, there are already tools to do this like xsel
and xclip, what's the use case for tmux doing it too?
xsel and xclip require X11 forwarding to be enabled in SSH to work.
And that's not all: I would have to update the $DISPLAY variable in
remote tmux sessions every time I reattach them for xsel and xclip.
In contrast, the set-clipboard functionality does not require X11
forwarding to be enabled and it also does not require any $DISPLAY
variable synchronization. It "Just Works", at the terminal level.
Since tmux already provides the set-clipboard functionality in the
`copy-mode` command, extending this functionality to the `setb` and
`loadb` commands would give me an easy and consistent way to copy
text from any shell within tmux to the (remotely) attached terminal.
Thanks for your consideration.
Loading...