diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2019-04-02 09:03:40 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2019-04-02 09:03:40 +0000 |
commit | db0fa372a961f9ae95e69ed401ec6c93c4a3eee4 (patch) | |
tree | 7df2c146efe72df316fbc0fdac351b40300740ac /usr.bin | |
parent | 5342d0744c57f49bf0cf8917f6a0674f81dd48cb (diff) |
Add an argument to copy commands to set the prefix for the buffer name,
allows buffers for different sessions to be named separately.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/tmux/input.c | 4 | ||||
-rw-r--r-- | usr.bin/tmux/paste.c | 11 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.1 | 25 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 4 | ||||
-rw-r--r-- | usr.bin/tmux/tty-keys.c | 4 | ||||
-rw-r--r-- | usr.bin/tmux/window-copy.c | 143 |
6 files changed, 134 insertions, 57 deletions
diff --git a/usr.bin/tmux/input.c b/usr.bin/tmux/input.c index c6eb27756ca..272729c9c6f 100644 --- a/usr.bin/tmux/input.c +++ b/usr.bin/tmux/input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: input.c,v 1.149 2019/03/14 09:53:52 nicm Exp $ */ +/* $OpenBSD: input.c,v 1.150 2019/04/02 09:03:39 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -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/usr.bin/tmux/paste.c b/usr.bin/tmux/paste.c index 9c77846010e..a6b925b05f0 100644 --- a/usr.bin/tmux/paste.c +++ b/usr.bin/tmux/paste.c @@ -1,4 +1,4 @@ -/* $OpenBSD: paste.c,v 1.39 2017/01/24 13:28:33 nicm Exp $ */ +/* $OpenBSD: paste.c,v 1.40 2019/04/02 09:03:39 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -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/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index bf9734ac43a..fb74b6d3bc4 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.632 2019/03/25 18:59:55 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.633 2019/04/02 09:03:39 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> .\" @@ -14,7 +14,7 @@ .\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING .\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: March 25 2019 $ +.Dd $Mdocdate: April 2 2019 $ .Dt TMUX 1 .Os .Sh NAME @@ -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/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 750ac755722..cafd3e752e2 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.878 2019/04/02 08:45:32 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.879 2019/04/02 09:03:39 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -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/usr.bin/tmux/tty-keys.c b/usr.bin/tmux/tty-keys.c index 3b12aaf9867..fe043c9b53f 100644 --- a/usr.bin/tmux/tty-keys.c +++ b/usr.bin/tmux/tty-keys.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty-keys.c,v 1.107 2019/03/18 11:58:40 nicm Exp $ */ +/* $OpenBSD: tty-keys.c,v 1.108 2019/04/02 09:03:39 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -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/usr.bin/tmux/window-copy.c b/usr.bin/tmux/window-copy.c index 4410750d765..f31ad83cb60 100644 --- a/usr.bin/tmux/window-copy.c +++ b/usr.bin/tmux/window-copy.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window-copy.c,v 1.214 2019/03/27 13:25:11 nicm Exp $ */ +/* $OpenBSD: window-copy.c,v 1.215 2019/04/02 09:03:39 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -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 |