summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cmd-load-buffer.c20
-rw-r--r--cmd-set-buffer.c10
-rw-r--r--tmux.119
-rw-r--r--tmux.h1
-rw-r--r--tty.c22
5 files changed, 57 insertions, 15 deletions
diff --git a/cmd-load-buffer.c b/cmd-load-buffer.c
index 49e834d6..f5a080be 100644
--- a/cmd-load-buffer.c
+++ b/cmd-load-buffer.c
@@ -37,14 +37,15 @@ const struct cmd_entry cmd_load_buffer_entry = {
.name = "load-buffer",
.alias = "loadb",
- .args = { "b:", 1, 1 },
- .usage = CMD_BUFFER_USAGE " path",
+ .args = { "b:t:w", 1, 1 },
+ .usage = CMD_BUFFER_USAGE " " CMD_TARGET_CLIENT_USAGE " path",
- .flags = CMD_AFTERHOOK,
+ .flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG|CMD_CLIENT_CANFAIL,
.exec = cmd_load_buffer_exec
};
struct cmd_load_buffer_data {
+ struct client *client;
struct cmdq_item *item;
char *name;
};
@@ -54,6 +55,7 @@ cmd_load_buffer_done(__unused struct client *c, const char *path, int error,
int closed, struct evbuffer *buffer, void *data)
{
struct cmd_load_buffer_data *cdata = data;
+ struct client *tc = cdata->client;
struct cmdq_item *item = cdata->item;
void *bdata = EVBUFFER_DATA(buffer);
size_t bsize = EVBUFFER_LENGTH(buffer);
@@ -72,7 +74,12 @@ cmd_load_buffer_done(__unused struct client *c, const char *path, int error,
cmdq_error(item, "%s", cause);
free(cause);
free(copy);
- }
+ } else if (tc != NULL &&
+ tc->session != NULL &&
+ (~tc->flags & CLIENT_DEAD))
+ tty_set_selection(&tc->tty, copy, bsize);
+ if (tc != NULL)
+ server_client_unref(tc);
}
cmdq_continue(item);
@@ -84,6 +91,7 @@ static enum cmd_retval
cmd_load_buffer_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = cmd_get_args(self);
+ struct client *tc = cmdq_get_target_client(item);
struct cmd_load_buffer_data *cdata;
const char *bufname = args_get(args, 'b');
char *path;
@@ -94,6 +102,10 @@ cmd_load_buffer_exec(struct cmd *self, struct cmdq_item *item)
cdata->name = xstrdup(bufname);
else
cdata->name = NULL;
+ if (args_has(args, 'w') && tc != NULL) {
+ cdata->client = tc;
+ cdata->client->references++;
+ }
path = format_single_from_target(item, args->argv[0]);
file_read(cmdq_get_client(item), path, cmd_load_buffer_done, cdata);
diff --git a/cmd-set-buffer.c b/cmd-set-buffer.c
index 0f3fffce..94d8cd52 100644
--- a/cmd-set-buffer.c
+++ b/cmd-set-buffer.c
@@ -33,10 +33,11 @@ const struct cmd_entry cmd_set_buffer_entry = {
.name = "set-buffer",
.alias = "setb",
- .args = { "ab:n:", 0, 1 },
- .usage = "[-a] " CMD_BUFFER_USAGE " [-n new-buffer-name] data",
+ .args = { "ab:t:n:w", 0, 1 },
+ .usage = "[-aw] " CMD_BUFFER_USAGE " [-n new-buffer-name] "
+ CMD_TARGET_CLIENT_USAGE " data",
- .flags = CMD_AFTERHOOK,
+ .flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG|CMD_CLIENT_CANFAIL,
.exec = cmd_set_buffer_exec
};
@@ -55,6 +56,7 @@ static enum cmd_retval
cmd_set_buffer_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = cmd_get_args(self);
+ struct client *tc = cmdq_get_target_client(item);
struct paste_buffer *pb;
char *bufdata, *cause;
const char *bufname, *olddata;
@@ -118,6 +120,8 @@ cmd_set_buffer_exec(struct cmd *self, struct cmdq_item *item)
free(cause);
return (CMD_RETURN_ERROR);
}
+ if (args_has(args, 'w') && tc != NULL)
+ tty_set_selection(&tc->tty, bufdata, bufsize);
return (CMD_RETURN_NORMAL);
}
diff --git a/tmux.1 b/tmux.1
index c11df7ce..08b329f4 100644
--- a/tmux.1
+++ b/tmux.1
@@ -5651,12 +5651,21 @@ See the
.Sx FORMATS
section.
.It Xo Ic load-buffer
+.Op Fl w
.Op Fl b Ar buffer-name
+.Op Fl t Ar target-client
.Ar path
.Xc
.D1 (alias: Ic loadb )
Load the contents of the specified paste buffer from
.Ar path .
+If
+.Fl w
+is given, the buffer is also sent to the clipboard for
+.Ar target-client
+using the
+.Xr xterm 1
+escape sequence, if possible.
.It Xo Ic paste-buffer
.Op Fl dpr
.Op Fl b Ar buffer-name
@@ -5693,14 +5702,22 @@ The
.Fl a
option appends to rather than overwriting the file.
.It Xo Ic set-buffer
-.Op Fl a
+.Op Fl aw
.Op Fl b Ar buffer-name
+.Op Fl t Ar target-client
.Op Fl n Ar new-buffer-name
.Ar data
.Xc
.D1 (alias: Ic setb )
Set the contents of the specified buffer to
.Ar data .
+If
+.Fl w
+is given, the buffer is also sent to the clipboard for
+.Ar target-client
+using the
+.Xr xterm 1
+escape sequence, if possible.
The
.Fl a
option appends to rather than overwriting the buffer.
diff --git a/tmux.h b/tmux.h
index 76953c3e..9fb3830a 100644
--- a/tmux.h
+++ b/tmux.h
@@ -2126,6 +2126,7 @@ int tty_open(struct tty *, char **);
void tty_close(struct tty *);
void tty_free(struct tty *);
void tty_update_features(struct tty *);
+void tty_set_selection(struct tty *, const char *, size_t);
void tty_write(void (*)(struct tty *, const struct tty_ctx *),
struct tty_ctx *);
void tty_cmd_alignmenttest(struct tty *, const struct tty_ctx *);
diff --git a/tty.c b/tty.c
index 14b770e2..148b1d2d 100644
--- a/tty.c
+++ b/tty.c
@@ -1896,19 +1896,27 @@ tty_cmd_cells(struct tty *tty, const struct tty_ctx *ctx)
void
tty_cmd_setselection(struct tty *tty, const struct tty_ctx *ctx)
{
- char *buf;
- size_t off;
+ tty_set_selection(tty, ctx->ptr, ctx->num);
+}
+
+void
+tty_set_selection(struct tty *tty, const char *buf, size_t len)
+{
+ char *encoded;
+ size_t size;
if (!tty_term_has(tty->term, TTYC_MS))
return;
+ if (~tty->flags & TTY_STARTED)
+ return;
- off = 4 * ((ctx->num + 2) / 3) + 1; /* storage for base64 */
- buf = xmalloc(off);
+ size = 4 * ((len + 2) / 3) + 1; /* storage for base64 */
+ encoded = xmalloc(size);
- b64_ntop(ctx->ptr, ctx->num, buf, off);
- tty_putcode_ptr2(tty, TTYC_MS, "", buf);
+ b64_ntop(buf, len, encoded, size);
+ tty_putcode_ptr2(tty, TTYC_MS, "", encoded);
- free(buf);
+ free(encoded);
}
void