summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicm <nicm>2019-04-02 09:03:39 +0000
committernicm <nicm>2019-04-02 09:03:39 +0000
commit7bcc0d16f24506bed6568ba36bcd278cfc06d069 (patch)
tree0dcb8ee612b7bb545bc7140b759e172628e9bbe8
parentffa4d489676f40582b63c1791d3bf5d3b75d8421 (diff)
Add an argument to copy commands to set the prefix for the buffer name,
allows buffers for different sessions to be named separately.
-rw-r--r--input.c2
-rw-r--r--paste.c9
-rw-r--r--tmux.121
-rw-r--r--tmux.h2
-rw-r--r--tty-keys.c2
-rw-r--r--window-copy.c141
6 files changed, 127 insertions, 50 deletions
diff --git a/input.c b/input.c
index 96793674..07341403 100644
--- a/input.c
+++ b/input.c
@@ -2432,7 +2432,7 @@ input_osc_52(struct input_ctx *ictx, const char *p)
screen_write_stop(&ctx);
notify_pane("pane-set-clipboard", wp);
- paste_add(out, outlen);
+ paste_add(NULL, out, outlen);
}
/* Handle the OSC 104 sequence for unsetting (multiple) palette entries. */
diff --git a/paste.c b/paste.c
index c76c52e5..0c9bc7b5 100644
--- a/paste.c
+++ b/paste.c
@@ -158,11 +158,14 @@ paste_free(struct paste_buffer *pb)
* that the caller is responsible for allocating data.
*/
void
-paste_add(char *data, size_t size)
+paste_add(const char *prefix, char *data, size_t size)
{
struct paste_buffer *pb, *pb1;
u_int limit;
+ if (prefix == NULL)
+ prefix = "buffer";
+
if (size == 0) {
free(data);
return;
@@ -181,7 +184,7 @@ paste_add(char *data, size_t size)
pb->name = NULL;
do {
free(pb->name);
- xasprintf(&pb->name, "buffer%04u", paste_next_index);
+ xasprintf(&pb->name, "%s%u", prefix, paste_next_index);
paste_next_index++;
} while (paste_get_name(pb->name) != NULL);
@@ -263,7 +266,7 @@ paste_set(char *data, size_t size, const char *name, char **cause)
return (0);
}
if (name == NULL) {
- paste_add(data, size);
+ paste_add(NULL, data, size);
return (0);
}
diff --git a/tmux.1 b/tmux.1
index e1c28fbb..d2960fb5 100644
--- a/tmux.1
+++ b/tmux.1
@@ -1132,12 +1132,12 @@ The following commands are supported in copy mode:
.It Li "bottom-line" Ta "L" Ta ""
.It Li "cancel" Ta "q" Ta "Escape"
.It Li "clear-selection" Ta "Escape" Ta "C-g"
-.It Li "copy-end-of-line" Ta "D" Ta "C-k"
-.It Li "copy-line" Ta "" Ta ""
-.It Li "copy-pipe <command>" Ta "" Ta ""
-.It Li "copy-pipe-and-cancel <command>" Ta "" Ta ""
-.It Li "copy-selection" Ta "" Ta ""
-.It Li "copy-selection-and-cancel" Ta "Enter" Ta "M-w"
+.It Li "copy-end-of-line [<prefix>]" Ta "D" Ta "C-k"
+.It Li "copy-line [<prefix>]" Ta "" Ta ""
+.It Li "copy-pipe <command> [<prefix>]" Ta "" Ta ""
+.It Li "copy-pipe-and-cancel <command> [<prefix>]" Ta "" Ta ""
+.It Li "copy-selection [<prefix>]" Ta "" Ta ""
+.It Li "copy-selection-and-cancel [<prefix>]" Ta "Enter" Ta "M-w"
.It Li "cursor-down" Ta "j" Ta "Down"
.It Li "cursor-left" Ta "h" Ta "Left"
.It Li "cursor-right" Ta "l" Ta "Right"
@@ -1184,6 +1184,15 @@ The following commands are supported in copy mode:
.It Li "top-line" Ta "H" Ta "M-R"
.El
.Pp
+Copy commands may take an optional buffer prefix argument which is used
+to generate the buffer name (the default is
+.Ql buffer
+so buffers are named
+.Ql buffer0 ,
+.Ql buffer1
+and so on).
+Pipe commands take a command argument which is the command to which the
+copied text is piped.
The
.Ql -and-cancel
variants of some commands exit copy mode after they have completed (for copy
diff --git a/tmux.h b/tmux.h
index 0821d790..31fbae32 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1611,7 +1611,7 @@ struct paste_buffer *paste_walk(struct paste_buffer *);
struct paste_buffer *paste_get_top(const char **);
struct paste_buffer *paste_get_name(const char *);
void paste_free(struct paste_buffer *);
-void paste_add(char *, size_t);
+void paste_add(const char *, char *, size_t);
int paste_rename(const char *, const char *, char **);
int paste_set(char *, size_t, const char *, char **);
char *paste_make_sample(struct paste_buffer *);
diff --git a/tty-keys.c b/tty-keys.c
index da84077b..7557eca0 100644
--- a/tty-keys.c
+++ b/tty-keys.c
@@ -976,7 +976,7 @@ tty_keys_clipboard(__unused struct tty *tty, const char *buf, size_t len,
/* Create a new paste buffer. */
log_debug("%s: %.*s", __func__, outlen, out);
- paste_add(out, outlen);
+ paste_add(NULL, out, outlen);
return (0);
}
diff --git a/window-copy.c b/window-copy.c
index b4fc7a2c..aacea5c5 100644
--- a/window-copy.c
+++ b/window-copy.c
@@ -79,11 +79,12 @@ static int window_copy_set_selection(struct window_mode_entry *, int);
static int window_copy_update_selection(struct window_mode_entry *, int);
static void window_copy_synchronize_cursor(struct window_mode_entry *);
static void *window_copy_get_selection(struct window_mode_entry *, size_t *);
-static void window_copy_copy_buffer(struct window_mode_entry *, void *,
- size_t);
+static void window_copy_copy_buffer(struct window_mode_entry *,
+ const char *, void *, size_t);
static void window_copy_copy_pipe(struct window_mode_entry *,
- struct session *, const char *);
-static void window_copy_copy_selection(struct window_mode_entry *);
+ struct session *, const char *, const char *);
+static void window_copy_copy_selection(struct window_mode_entry *,
+ const char *);
static void window_copy_append_selection(struct window_mode_entry *);
static void window_copy_clear_selection(struct window_mode_entry *);
static void window_copy_copy_line(struct window_mode_entry *, char **,
@@ -164,8 +165,10 @@ struct window_copy_cmd_state {
struct window_mode_entry *wme;
struct args *args;
struct mouse_event *m;
+
struct client *c;
struct session *s;
+ struct winlink *wl;
};
/*
@@ -673,8 +676,15 @@ static enum window_copy_cmd_action
window_copy_cmd_copy_end_of_line(struct window_copy_cmd_state *cs)
{
struct window_mode_entry *wme = cs->wme;
+ struct client *c = cs->c;
struct session *s = cs->s;
+ struct winlink *wl = cs->wl;
+ struct window_pane *wp = wme->wp;
u_int np = wme->prefix;
+ char *prefix = NULL;
+
+ if (cs->args->argc == 2)
+ prefix = format_single(NULL, cs->args->argv[1], c, s, wl, wp);
window_copy_start_selection(wme);
for (; np > 1; np--)
@@ -682,9 +692,13 @@ window_copy_cmd_copy_end_of_line(struct window_copy_cmd_state *cs)
window_copy_cursor_end_of_line(wme);
if (s != NULL) {
- window_copy_copy_selection(wme);
+ window_copy_copy_selection(wme, prefix);
+
+ free(prefix);
return (WINDOW_COPY_CMD_CANCEL);
}
+
+ free(prefix);
return (WINDOW_COPY_CMD_REDRAW);
}
@@ -692,8 +706,15 @@ static enum window_copy_cmd_action
window_copy_cmd_copy_line(struct window_copy_cmd_state *cs)
{
struct window_mode_entry *wme = cs->wme;
+ struct client *c = cs->c;
struct session *s = cs->s;
+ struct winlink *wl = cs->wl;
+ struct window_pane *wp = wme->wp;
u_int np = wme->prefix;
+ char *prefix = NULL;
+
+ if (cs->args->argc == 2)
+ prefix = format_single(NULL, cs->args->argv[1], c, s, wl, wp);
window_copy_cursor_start_of_line(wme);
window_copy_start_selection(wme);
@@ -702,9 +723,13 @@ window_copy_cmd_copy_line(struct window_copy_cmd_state *cs)
window_copy_cursor_end_of_line(wme);
if (s != NULL) {
- window_copy_copy_selection(wme);
+ window_copy_copy_selection(wme, prefix);
+
+ free(prefix);
return (WINDOW_COPY_CMD_CANCEL);
}
+
+ free(prefix);
return (WINDOW_COPY_CMD_REDRAW);
}
@@ -712,11 +737,20 @@ static enum window_copy_cmd_action
window_copy_cmd_copy_selection(struct window_copy_cmd_state *cs)
{
struct window_mode_entry *wme = cs->wme;
+ struct client *c = cs->c;
struct session *s = cs->s;
+ struct winlink *wl = cs->wl;
+ struct window_pane *wp = wme->wp;
+ char *prefix = NULL;
+
+ if (cs->args->argc == 2)
+ prefix = format_single(NULL, cs->args->argv[1], c, s, wl, wp);
if (s != NULL)
- window_copy_copy_selection(wme);
+ window_copy_copy_selection(wme, prefix);
window_copy_clear_selection(wme);
+
+ free(prefix);
return (WINDOW_COPY_CMD_REDRAW);
}
@@ -724,11 +758,20 @@ static enum window_copy_cmd_action
window_copy_cmd_copy_selection_and_cancel(struct window_copy_cmd_state *cs)
{
struct window_mode_entry *wme = cs->wme;
+ struct client *c = cs->c;
struct session *s = cs->s;
+ struct winlink *wl = cs->wl;
+ struct window_pane *wp = wme->wp;
+ char *prefix = NULL;
+
+ if (cs->args->argc == 2)
+ prefix = format_single(NULL, cs->args->argv[1], c, s, wl, wp);
if (s != NULL)
- window_copy_copy_selection(wme);
+ window_copy_copy_selection(wme, prefix);
window_copy_clear_selection(wme);
+
+ free(prefix);
return (WINDOW_COPY_CMD_CANCEL);
}
@@ -1216,11 +1259,23 @@ static enum window_copy_cmd_action
window_copy_cmd_copy_pipe(struct window_copy_cmd_state *cs)
{
struct window_mode_entry *wme = cs->wme;
+ struct client *c = cs->c;
struct session *s = cs->s;
- const char *argument = cs->args->argv[1];
+ struct winlink *wl = cs->wl;
+ struct window_pane *wp = wme->wp;
+ char *command = NULL;
+ char *prefix = NULL;
+
+ if (cs->args->argc == 3)
+ prefix = format_single(NULL, cs->args->argv[2], c, s, wl, wp);
- if (s != NULL && *argument != '\0')
- window_copy_copy_pipe(wme, s, argument);
+ if (s != NULL && *cs->args->argv[1] != '\0') {
+ command = format_single(NULL, cs->args->argv[1], c, s, wl, wp);
+ window_copy_copy_pipe(wme, s, prefix, command);
+ free(command);
+ }
+
+ free(prefix);
return (WINDOW_COPY_CMD_NOTHING);
}
@@ -1228,13 +1283,26 @@ static enum window_copy_cmd_action
window_copy_cmd_copy_pipe_and_cancel(struct window_copy_cmd_state *cs)
{
struct window_mode_entry *wme = cs->wme;
+ struct client *c = cs->c;
struct session *s = cs->s;
- const char *argument = cs->args->argv[1];
+ struct winlink *wl = cs->wl;
+ struct window_pane *wp = wme->wp;
+ char *command = NULL;
+ char *prefix = NULL;
+
+ if (cs->args->argc == 3)
+ prefix = format_single(NULL, cs->args->argv[2], c, s, wl, wp);
+
+ if (s != NULL && *cs->args->argv[1] != '\0') {
+ command = format_single(NULL, cs->args->argv[1], c, s, wl, wp);
+ window_copy_copy_pipe(wme, s, prefix, command);
+ free(command);
- if (s != NULL && *argument != '\0') {
- window_copy_copy_pipe(wme, s, argument);
+ free(prefix);
return (WINDOW_COPY_CMD_CANCEL);
}
+
+ free(prefix);
return (WINDOW_COPY_CMD_NOTHING);
}
@@ -1278,7 +1346,7 @@ window_copy_cmd_jump_forward(struct window_copy_cmd_state *cs)
data->jumptype = WINDOW_COPY_JUMPFORWARD;
data->jumpchar = *argument;
for (; np != 0; np--)
- window_copy_cursor_jump(wme);
+ window_copy_cursor_jump(wme);
}
return (WINDOW_COPY_CMD_NOTHING);
}
@@ -1470,17 +1538,17 @@ static const struct {
window_copy_cmd_cancel },
{ "clear-selection", 0, 0,
window_copy_cmd_clear_selection },
- { "copy-end-of-line", 0, 0,
+ { "copy-end-of-line", 0, 1,
window_copy_cmd_copy_end_of_line },
- { "copy-line", 0, 0,
+ { "copy-line", 0, 1,
window_copy_cmd_copy_line },
- { "copy-pipe", 1, 1,
+ { "copy-pipe", 1, 2,
window_copy_cmd_copy_pipe },
- { "copy-pipe-and-cancel", 1, 1,
+ { "copy-pipe-and-cancel", 1, 2,
window_copy_cmd_copy_pipe_and_cancel },
- { "copy-selection", 0, 0,
+ { "copy-selection", 0, 1,
window_copy_cmd_copy_selection },
- { "copy-selection-and-cancel", 0, 0,
+ { "copy-selection-and-cancel", 0, 1,
window_copy_cmd_copy_selection_and_cancel },
{ "cursor-down", 0, 0,
window_copy_cmd_cursor_down },
@@ -1576,7 +1644,7 @@ static const struct {
static void
window_copy_command(struct window_mode_entry *wme, struct client *c,
- struct session *s, __unused struct winlink *wl, struct args *args,
+ struct session *s, struct winlink *wl, struct args *args,
struct mouse_event *m)
{
struct window_copy_mode_data *data = wme->data;
@@ -1595,8 +1663,10 @@ window_copy_command(struct window_mode_entry *wme, struct client *c,
cs.wme = wme;
cs.args = args;
cs.m = m;
+
cs.c = c;
cs.s = s;
+ cs.wl = wl;
action = WINDOW_COPY_CMD_NOTHING;
for (i = 0; i < nitems(window_copy_cmd_table); i++) {
@@ -2331,7 +2401,8 @@ window_copy_get_selection(struct window_mode_entry *wme, size_t *len)
}
static void
-window_copy_copy_buffer(struct window_mode_entry *wme, void *buf, size_t len)
+window_copy_copy_buffer(struct window_mode_entry *wme, const char *prefix,
+ void *buf, size_t len)
{
struct window_pane *wp = wme->wp;
struct screen_write_ctx ctx;
@@ -2343,41 +2414,35 @@ window_copy_copy_buffer(struct window_mode_entry *wme, void *buf, size_t len)
notify_pane("pane-set-clipboard", wp);
}
- if (paste_set(buf, len, NULL, NULL) != 0)
- free(buf);
+ paste_add(prefix, buf, len);
}
static void
window_copy_copy_pipe(struct window_mode_entry *wme, struct session *s,
- const char *fmt)
+ const char *prefix, const char *command)
{
- struct window_pane *wp = wme->wp;
- void *buf;
- size_t len;
- struct job *job;
- char *expanded;
+ void *buf;
+ size_t len;
+ struct job *job;
buf = window_copy_get_selection(wme, &len);
if (buf == NULL)
return;
- expanded = format_single(NULL, fmt, NULL, s, NULL, wp);
- job = job_run(expanded, s, NULL, NULL, NULL, NULL, NULL, JOB_NOWAIT);
+ job = job_run(command, s, NULL, NULL, NULL, NULL, NULL, JOB_NOWAIT);
bufferevent_write(job_get_event(job), buf, len);
-
- free(expanded);
- window_copy_copy_buffer(wme, buf, len);
+ window_copy_copy_buffer(wme, prefix, buf, len);
}
static void
-window_copy_copy_selection(struct window_mode_entry *wme)
+window_copy_copy_selection(struct window_mode_entry *wme, const char *prefix)
{
char *buf;
size_t len;
buf = window_copy_get_selection(wme, &len);
if (buf != NULL)
- window_copy_copy_buffer(wme, buf, len);
+ window_copy_copy_buffer(wme, prefix, buf, len);
}
static void