-/* $OpenBSD: cmd-confirm-before.c,v 1.52 2021/10/28 18:39:15 nicm Exp $ */
+/* $OpenBSD: cmd-confirm-before.c,v 1.53 2023/04/28 06:12:27 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
.name = "confirm-before",
.alias = "confirm",
- .args = { "bp:t:", 1, 1, cmd_confirm_before_args_parse },
- .usage = "[-b] [-p prompt] " CMD_TARGET_CLIENT_USAGE " command",
+ .args = { "bc:p:t:y", 1, 1, cmd_confirm_before_args_parse },
+ .usage = "[-by] [-c confirm_key] [-p prompt] " CMD_TARGET_CLIENT_USAGE
+ " command",
.flags = CMD_CLIENT_TFLAG,
.exec = cmd_confirm_before_exec
struct cmd_confirm_before_data {
struct cmdq_item *item;
struct cmd_list *cmdlist;
+ u_char confirm_key;
+ int default_yes;
};
static enum args_parse_type
struct client *tc = cmdq_get_target_client(item);
struct cmd_find_state *target = cmdq_get_target(item);
char *new_prompt;
- const char *prompt, *cmd;
+ const char *confirm_key, *prompt, *cmd;
int wait = !args_has(args, 'b');
cdata = xcalloc(1, sizeof *cdata);
if (wait)
cdata->item = item;
+ cdata->default_yes = args_has(args, 'y');
+ if ((confirm_key = args_get(args, 'c')) != NULL) {
+ if (confirm_key[1] == '\0' &&
+ confirm_key[0] > 31 &&
+ confirm_key[0] < 127)
+ cdata->confirm_key = confirm_key[0];
+ else {
+ cmdq_error(item, "invalid confirm key");
+ return (CMD_RETURN_ERROR);
+ }
+ }
+ else
+ cdata->confirm_key = 'y';
+
if ((prompt = args_get(args, 'p')) != NULL)
xasprintf(&new_prompt, "%s ", prompt);
else {
cmd = cmd_get_entry(cmd_list_first(cdata->cmdlist))->name;
- xasprintf(&new_prompt, "Confirm '%s'? (y/n) ", cmd);
+ xasprintf(&new_prompt, "Confirm '%s'? (%c/n) ",
+ cmd, cdata->confirm_key);
}
status_prompt_set(tc, target, new_prompt, NULL,
if (c->flags & CLIENT_DEAD)
goto out;
- if (s == NULL || *s == '\0')
+ if (s == NULL)
goto out;
- if (tolower((u_char)s[0]) != 'y' || s[1] != '\0')
+ if (s[0] != cdata->confirm_key && (s[0] != '\0' || !cdata->default_yes))
goto out;
retcode = 0;
}
out:
- if (item != NULL) {
- if (cmdq_get_client(item) != NULL &&
- cmdq_get_client(item)->session == NULL)
- cmdq_get_client(item)->retval = retcode;
- 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: tmux.1,v 1.918 2023/04/03 07:39:37 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.919 2023/04/28 06:12:27 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: April 3 2023 $
+.Dd $Mdocdate: April 28 2023 $
.Dt TMUX 1
.Os
.Sh NAME
until it is dismissed.
.Tg confirm
.It Xo Ic confirm-before
-.Op Fl b
+.Op Fl by
+.Op Fl c Ar confirm-key
.Op Fl p Ar prompt
.Op Fl t Ar target-client
.Ar command
.Fl b ,
the prompt is shown in the background and the invoking client does not exit
until it is dismissed.
+.Fl y
+changes the default behaviour (if Enter alone is pressed) of the prompt to
+run the command.
+.Fl c
+changes the confirmation key to
+.Ar confirm-key ;
+the default is
+.Ql y .
.Tg menu
.It Xo Ic display-menu
.Op Fl O