GitHub issue 2822.
-/* $OpenBSD: cmd-command-prompt.c,v 1.55 2021/06/10 07:52:56 nicm Exp $ */
+/* $OpenBSD: cmd-command-prompt.c,v 1.56 2021/08/13 06:50:42 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
.name = "command-prompt",
.alias = NULL,
- .args = { "1FkiI:Np:t:T:", 0, 1 },
- .usage = "[-1FkiN] [-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE
+ .args = { "1bFkiI:Np:t:T:", 0, 1 },
+ .usage = "[-1bFkiN] [-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE
" [-T type] [template]",
.flags = CMD_CLIENT_TFLAG,
};
struct cmd_command_prompt_cdata {
- int flags;
- enum prompt_type prompt_type;
+ struct cmdq_item *item;
+ struct cmd_parse_input pi;
- char *inputs;
- char *next_input;
+ int flags;
+ enum prompt_type prompt_type;
- char *prompts;
- char *next_prompt;
+ char *inputs;
+ char *next_input;
- char *template;
- int idx;
+ char *prompts;
+ char *next_prompt;
+
+ char *template;
+ int idx;
};
static enum cmd_retval
struct cmd_command_prompt_cdata *cdata;
char *prompt, *ptr, *input = NULL;
size_t n;
+ int wait = !args_has(args, 'b');
if (tc->prompt_string != NULL)
return (CMD_RETURN_NORMAL);
cdata = xcalloc(1, sizeof *cdata);
+ cdata->idx = 1;
- cdata->inputs = NULL;
- cdata->next_input = NULL;
-
- cdata->prompts = NULL;
- cdata->next_prompt = NULL;
+ cmd_get_source(self, &cdata->pi.file, &cdata->pi.line);
+ if (wait)
+ cdata->pi.item = item;
+ cdata->pi.c = tc;
+ cmd_find_copy_state(&cdata->pi.fs, target);
- cdata->template = NULL;
- cdata->idx = 1;
+ if (wait)
+ cdata->item = item;
if (args->argc != 0 && args_has(args, 'F'))
cdata->template = format_single_from_target(item, args->argv[0]);
cdata->flags, cdata->prompt_type);
free(prompt);
- return (CMD_RETURN_NORMAL);
+ if (!wait)
+ return (CMD_RETURN_NORMAL);
+ return (CMD_RETURN_WAIT);
}
static int
struct cmd_command_prompt_cdata *cdata = data;
char *new_template, *prompt, *ptr, *error;
char *input = NULL;
+ struct cmdq_item *item = cdata->item;
enum cmd_parse_status status;
if (s == NULL)
- return (0);
+ goto out;
if (done && (cdata->flags & PROMPT_INCREMENTAL))
- return (0);
+ goto out;
new_template = cmd_template_replace(cdata->template, s, cdata->idx);
if (done) {
return (1);
}
- status = cmd_parse_and_append(new_template, NULL, c, NULL, &error);
+ if (item != NULL) {
+ status = cmd_parse_and_insert(new_template, &cdata->pi, item,
+ cmdq_get_state(item), &error);
+ } else {
+ status = cmd_parse_and_append(new_template, &cdata->pi, c, NULL,
+ &error);
+ }
if (status == CMD_PARSE_ERROR) {
cmdq_append(c, cmdq_get_error(error));
free(error);
free(new_template);
if (c->prompt_inputcb != cmd_command_prompt_callback)
return (1);
+
+out:
+ if (item != NULL)
+ cmdq_continue(item);
return (0);
}
-/* $OpenBSD: cmd-confirm-before.c,v 1.44 2021/08/11 08:40:58 nicm Exp $ */
+/* $OpenBSD: cmd-confirm-before.c,v 1.45 2021/08/13 06:50:42 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
cdata = xmalloc(sizeof *cdata);
cdata->cmd = xstrdup(args->argv[0]);
- memset(&cdata->pi, 0, sizeof cdata->pi);
cmd_get_source(self, &cdata->pi.file, &cdata->pi.line);
if (wait)
cdata->pi.item = item;
status_prompt_set(tc, target, new_prompt, NULL,
cmd_confirm_before_callback, cmd_confirm_before_free, cdata,
PROMPT_SINGLE, PROMPT_TYPE_COMMAND);
-
free(new_prompt);
+
if (!wait)
return (CMD_RETURN_NORMAL);
return (CMD_RETURN_WAIT);
char *error;
struct cmdq_item *item = cdata->item;
enum cmd_parse_status status;
+ int retcode = 1;
if (c->flags & CLIENT_DEAD)
- return (0);
+ goto out;
if (s == NULL || *s == '\0')
goto out;
if (tolower((u_char)s[0]) != 'y' || s[1] != '\0')
goto out;
+ retcode = 0;
if (item != NULL) {
status = cmd_parse_and_insert(cmd, &cdata->pi, item,
}
out:
- if (item != NULL)
- cmdq_continue(item);
+ if (item != NULL) {
+ if (cmdq_get_client(item) != NULL &&
+ cmdq_get_client(item)->session == NULL)
+ cmdq_get_client(item)->retval = retcode;
+ cmdq_continue(item);
+ }
return (0);
}
-/* $OpenBSD: cmd-if-shell.c,v 1.75 2021/03/02 10:56:45 nicm Exp $ */
+/* $OpenBSD: cmd-if-shell.c,v 1.76 2021/08/13 06:50:42 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
cdata->cmd_if = xstrdup(args->argv[1]);
if (args->argc == 3)
cdata->cmd_else = xstrdup(args->argv[2]);
- else
- cdata->cmd_else = NULL;
if (!args_has(args, 'b'))
cdata->client = cmdq_get_client(item);
if (!args_has(args, 'b'))
cdata->item = item;
- else
- cdata->item = NULL;
- memset(&cdata->input, 0, sizeof cdata->input);
cmd_get_source(self, &file, &cdata->input.line);
if (file != NULL)
cdata->input.file = xstrdup(file);
-/* $OpenBSD: cmd-run-shell.c,v 1.73 2021/04/12 09:36:12 nicm Exp $ */
+/* $OpenBSD: cmd-run-shell.c,v 1.74 2021/08/13 06:50:42 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
cdata->shell = !args_has(args, 'C');
if (!cdata->shell) {
- memset(&cdata->pi, 0, sizeof cdata->pi);
cmd_get_source(self, &cdata->pi.file, &cdata->pi.line);
if (wait)
cdata->pi.item = item;
-.\" $OpenBSD: tmux.1,v 1.851 2021/08/12 08:05:11 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.852 2021/08/13 06:50:42 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.\"
.\" 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: August 12 2021 $
+.Dd $Mdocdate: August 13 2021 $
.Dt TMUX 1
.Os
.Sh NAME
for possible values for
.Ar prompt-type .
.It Xo Ic command-prompt
-.Op Fl 1FikN
+.Op Fl 1bFikN
.Op Fl I Ar inputs
.Op Fl p Ar prompts
.Op Fl t Ar target-client
.It Li "Move cursor to previous word" Ta "b" Ta "M-b"
.It Li "Move cursor to start" Ta "0" Ta "C-a"
.It Li "Transpose characters" Ta "" Ta "C-t"
+.Pp
.El
+With
+.Fl b ,
+the prompt is shown in the background and the invoking client does not exit
+until it is dismissed.
.It Xo Ic confirm-before
.Op Fl b
.Op Fl p Ar prompt
option.
With
.Fl b ,
-the prompt is shown in the background and the client.
+the prompt is shown in the background and the invoking client does not exit
+until it is dismissed.
.It Xo Ic display-menu
.Op Fl O
.Op Fl c Ar target-client