From 04d313c5ecc70eb438155861372bc182aea5c3a7 Mon Sep 17 00:00:00 2001 From: nicm Date: Fri, 15 Sep 2023 06:31:49 +0000 Subject: [PATCH] Add -t to source-file, GitHub issue 3473. --- usr.bin/tmux/cfg.c | 25 ++++++++++++------------- usr.bin/tmux/cmd-queue.c | 6 ++++-- usr.bin/tmux/cmd-source-file.c | 11 +++++++---- usr.bin/tmux/input.c | 4 ++-- usr.bin/tmux/tmux.1 | 5 +++-- usr.bin/tmux/tmux.h | 12 +++++++----- 6 files changed, 35 insertions(+), 28 deletions(-) diff --git a/usr.bin/tmux/cfg.c b/usr.bin/tmux/cfg.c index 286c0017538..9da91532be8 100644 --- a/usr.bin/tmux/cfg.c +++ b/usr.bin/tmux/cfg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cfg.c,v 1.86 2022/06/20 07:59:37 nicm Exp $ */ +/* $OpenBSD: cfg.c,v 1.87 2023/09/15 06:31:49 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott @@ -67,6 +67,7 @@ start_cfg(void) { struct client *c; u_int i; + int flags = 0; /* * Configuration files are loaded without a client, so commands are run @@ -84,19 +85,17 @@ start_cfg(void) cmdq_append(c, cfg_item); } - for (i = 0; i < cfg_nfiles; i++) { - if (cfg_quiet) - load_cfg(cfg_files[i], c, NULL, CMD_PARSE_QUIET, NULL); - else - load_cfg(cfg_files[i], c, NULL, 0, NULL); - } + if (cfg_quiet) + flags = CMD_PARSE_QUIET; + for (i = 0; i < cfg_nfiles; i++) + load_cfg(cfg_files[i], c, NULL, NULL, flags, NULL); cmdq_append(NULL, cmdq_get_callback(cfg_done, NULL)); } int -load_cfg(const char *path, struct client *c, struct cmdq_item *item, int flags, - struct cmdq_item **new_item) +load_cfg(const char *path, struct client *c, struct cmdq_item *item, + struct cmd_find_state *current, int flags, struct cmdq_item **new_item) { FILE *f; struct cmd_parse_input pi; @@ -135,7 +134,7 @@ load_cfg(const char *path, struct client *c, struct cmdq_item *item, int flags, } if (item != NULL) - state = cmdq_copy_state(cmdq_get_state(item)); + state = cmdq_copy_state(cmdq_get_state(item), current); else state = cmdq_new_state(NULL, NULL, 0); cmdq_add_format(state, "current_file", "%s", pi.file); @@ -155,8 +154,8 @@ load_cfg(const char *path, struct client *c, struct cmdq_item *item, int flags, int load_cfg_from_buffer(const void *buf, size_t len, const char *path, - struct client *c, struct cmdq_item *item, int flags, - struct cmdq_item **new_item) + struct client *c, struct cmdq_item *item, struct cmd_find_state *current, + int flags, struct cmdq_item **new_item) { struct cmd_parse_input pi; struct cmd_parse_result *pr; @@ -187,7 +186,7 @@ load_cfg_from_buffer(const void *buf, size_t len, const char *path, } if (item != NULL) - state = cmdq_copy_state(cmdq_get_state(item)); + state = cmdq_copy_state(cmdq_get_state(item), current); else state = cmdq_new_state(NULL, NULL, 0); cmdq_add_format(state, "current_file", "%s", pi.file); diff --git a/usr.bin/tmux/cmd-queue.c b/usr.bin/tmux/cmd-queue.c index dc13d3a7bda..3ce516803f0 100644 --- a/usr.bin/tmux/cmd-queue.c +++ b/usr.bin/tmux/cmd-queue.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-queue.c,v 1.114 2023/02/05 21:15:32 nicm Exp $ */ +/* $OpenBSD: cmd-queue.c,v 1.115 2023/09/15 06:31:49 nicm Exp $ */ /* * Copyright (c) 2013 Nicholas Marriott @@ -237,8 +237,10 @@ cmdq_link_state(struct cmdq_state *state) /* Make a copy of a state. */ struct cmdq_state * -cmdq_copy_state(struct cmdq_state *state) +cmdq_copy_state(struct cmdq_state *state, struct cmd_find_state *current) { + if (current != NULL) + return (cmdq_new_state(current, &state->event, state->flags)); return (cmdq_new_state(&state->current, &state->event, state->flags)); } diff --git a/usr.bin/tmux/cmd-source-file.c b/usr.bin/tmux/cmd-source-file.c index fde4225ae70..83c29bf6544 100644 --- a/usr.bin/tmux/cmd-source-file.c +++ b/usr.bin/tmux/cmd-source-file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-source-file.c,v 1.53 2021/08/23 11:04:21 nicm Exp $ */ +/* $OpenBSD: cmd-source-file.c,v 1.54 2023/09/15 06:31:49 nicm Exp $ */ /* * Copyright (c) 2008 Tiago Cunha @@ -36,8 +36,10 @@ const struct cmd_entry cmd_source_file_entry = { .name = "source-file", .alias = "source", - .args = { "Fnqv", 1, -1, NULL }, - .usage = "[-Fnqv] path ...", + .args = { "t:Fnqv", 1, -1, NULL }, + .usage = "[-Fnqv] " CMD_TARGET_PANE_USAGE " path ...", + + .target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL }, .flags = 0, .exec = cmd_source_file_exec @@ -93,6 +95,7 @@ cmd_source_file_done(struct client *c, const char *path, int error, size_t bsize = EVBUFFER_LENGTH(buffer); u_int n; struct cmdq_item *new_item; + struct cmd_find_state *target = cmdq_get_target(item); if (!closed) return; @@ -101,7 +104,7 @@ cmd_source_file_done(struct client *c, const char *path, int error, cmdq_error(item, "%s: %s", path, strerror(error)); else if (bsize != 0) { if (load_cfg_from_buffer(bdata, bsize, path, c, cdata->after, - cdata->flags, &new_item) < 0) + target, cdata->flags, &new_item) < 0) cdata->retval = CMD_RETURN_ERROR; else if (new_item != NULL) cdata->after = new_item; diff --git a/usr.bin/tmux/input.c b/usr.bin/tmux/input.c index ae9f6f27d54..b6396a9cb21 100644 --- a/usr.bin/tmux/input.c +++ b/usr.bin/tmux/input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: input.c,v 1.221 2023/09/15 06:28:15 nicm Exp $ */ +/* $OpenBSD: input.c,v 1.222 2023/09/15 06:31:49 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -1835,7 +1835,7 @@ input_csi_dispatch_sm_private(struct input_ctx *ictx) /* Handle CSI graphics SM. */ static void -input_csi_dispatch_sm_graphics(struct input_ctx *ictx) +input_csi_dispatch_sm_graphics(__unused struct input_ctx *ictx) { } diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index 4a33de855b7..5f6bc7d9f27 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.931 2023/09/02 09:17:23 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.932 2023/09/15 06:31:49 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott .\" @@ -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: September 2 2023 $ +.Dd $Mdocdate: September 15 2023 $ .Dt TMUX 1 .Os .Sh NAME @@ -1546,6 +1546,7 @@ show debugging information about jobs and terminals. .Tg source .It Xo Ic source-file .Op Fl Fnqv +.Op Fl t Ar target-pane .Ar path ... .Xc .D1 Pq alias: Ic source diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 74a86482af4..18d0da107cc 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.1209 2023/09/02 20:03:10 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.1210 2023/09/15 06:31:49 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -2102,10 +2102,11 @@ extern char **cfg_files; extern u_int cfg_nfiles; extern int cfg_quiet; void start_cfg(void); -int load_cfg(const char *, struct client *, struct cmdq_item *, int, - struct cmdq_item **); +int load_cfg(const char *, struct client *, struct cmdq_item *, + struct cmd_find_state *, int, struct cmdq_item **); int load_cfg_from_buffer(const void *, size_t, const char *, - struct client *, struct cmdq_item *, int, struct cmdq_item **); + struct client *, struct cmdq_item *, struct cmd_find_state *, + int, struct cmdq_item **); void printflike(1, 2) cfg_add_cause(const char *, ...); void cfg_print_causes(struct cmdq_item *); void cfg_show_causes(struct session *); @@ -2551,7 +2552,8 @@ struct cmd_parse_result *cmd_parse_from_arguments(struct args_value *, u_int, struct cmdq_state *cmdq_new_state(struct cmd_find_state *, struct key_event *, int); struct cmdq_state *cmdq_link_state(struct cmdq_state *); -struct cmdq_state *cmdq_copy_state(struct cmdq_state *); +struct cmdq_state *cmdq_copy_state(struct cmdq_state *, + struct cmd_find_state *); void cmdq_free_state(struct cmdq_state *); void printflike(3, 4) cmdq_add_format(struct cmdq_state *, const char *, const char *, ...); -- 2.20.1