-/* $OpenBSD: cmd-confirm-before.c,v 1.43 2021/06/10 07:50:03 nicm Exp $ */
+/* $OpenBSD: cmd-confirm-before.c,v 1.44 2021/08/11 08:40:58 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
.name = "confirm-before",
.alias = "confirm",
- .args = { "p:t:", 1, 1 },
- .usage = "[-p prompt] " CMD_TARGET_CLIENT_USAGE " command",
+ .args = { "bp:t:", 1, 1 },
+ .usage = "[-b] [-p prompt] " CMD_TARGET_CLIENT_USAGE " command",
.flags = CMD_CLIENT_TFLAG,
.exec = cmd_confirm_before_exec
};
struct cmd_confirm_before_data {
- char *cmd;
+ char *cmd;
+ struct cmdq_item *item;
+ struct cmd_parse_input pi;
};
static enum cmd_retval
struct cmd_find_state *target = cmdq_get_target(item);
char *cmd, *copy, *new_prompt, *ptr;
const char *prompt;
+ int wait = !args_has(args, 'b');
if ((prompt = args_get(args, 'p')) != NULL)
xasprintf(&new_prompt, "%s ", prompt);
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;
+ cdata->pi.c = tc;
+ cmd_find_copy_state(&cdata->pi.fs, target);
+
+ if (wait)
+ cdata->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);
- return (CMD_RETURN_NORMAL);
+ if (!wait)
+ return (CMD_RETURN_NORMAL);
+ return (CMD_RETURN_WAIT);
}
static int
__unused int done)
{
struct cmd_confirm_before_data *cdata = data;
+ const char *cmd = cdata->cmd;
char *error;
+ struct cmdq_item *item = cdata->item;
enum cmd_parse_status status;
if (c->flags & CLIENT_DEAD)
return (0);
if (s == NULL || *s == '\0')
- return (0);
+ goto out;
if (tolower((u_char)s[0]) != 'y' || s[1] != '\0')
- return (0);
+ goto out;
- status = cmd_parse_and_append(cdata->cmd, NULL, c, NULL, &error);
+ if (item != NULL) {
+ status = cmd_parse_and_insert(cmd, &cdata->pi, item,
+ cmdq_get_state(item), &error);
+ } else
+ status = cmd_parse_and_append(cmd, &cdata->pi, c, NULL, &error);
if (status == CMD_PARSE_ERROR) {
cmdq_append(c, cmdq_get_error(error));
free(error);
}
+out:
+ if (item != NULL)
+ cmdq_continue(item);
return (0);
}
-.\" $OpenBSD: tmux.1,v 1.847 2021/08/09 13:08:08 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.848 2021/08/11 08:40:58 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 9 2021 $
+.Dd $Mdocdate: August 11 2021 $
.Dt TMUX 1
.Os
.Sh NAME
.It Li "Transpose characters" Ta "" Ta "C-t"
.El
.It Xo Ic confirm-before
+.Op Fl b
.Op Fl p Ar prompt
.Op Fl t Ar target-client
.Ar command
It may contain the special character sequences supported by the
.Ic status-left
option.
-.Pp
-This command works only from inside
-.Nm .
+With
+.Fl b ,
+the prompt is shown in the background and the client.
.It Xo Ic display-menu
.Op Fl O
.Op Fl c Ar target-client