diff options
author | 2011-07-08 06:37:57 +0000 | |
---|---|---|
committer | 2011-07-08 06:37:57 +0000 | |
commit | 3041f374c57c5bb526c372f1d9abd73b35fef52f (patch) | |
tree | 22667d0214e4af55a863c49f67e0dfb73eab2938 /usr.bin/tmux/cmd-confirm-before.c | |
parent | Fix a couple of comments. (diff) | |
download | wireguard-openbsd-3041f374c57c5bb526c372f1d9abd73b35fef52f.tar.xz wireguard-openbsd-3041f374c57c5bb526c372f1d9abd73b35fef52f.zip |
Make confirm-before prompt customizable with -p option like
command-prompt. Also move responsibility for calling status_replace into
status_prompt_{set,update} and add #W and #P to the default kill-window
and kill-pane prompts. By Tiago Cunha.
Diffstat (limited to 'usr.bin/tmux/cmd-confirm-before.c')
-rw-r--r-- | usr.bin/tmux/cmd-confirm-before.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/usr.bin/tmux/cmd-confirm-before.c b/usr.bin/tmux/cmd-confirm-before.c index 627cd7ae160..160cbd4e0d1 100644 --- a/usr.bin/tmux/cmd-confirm-before.c +++ b/usr.bin/tmux/cmd-confirm-before.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-confirm-before.c,v 1.11 2011/07/02 21:05:44 nicm Exp $ */ +/* $OpenBSD: cmd-confirm-before.c,v 1.12 2011/07/08 06:37:57 nicm Exp $ */ /* * Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org> @@ -33,8 +33,8 @@ void cmd_confirm_before_free(void *); const struct cmd_entry cmd_confirm_before_entry = { "confirm-before", "confirm", - "t:", 1, 1, - CMD_TARGET_CLIENT_USAGE " command", + "p:t:", 1, 1, + "[-p prompt] " CMD_TARGET_CLIENT_USAGE " command", 0, cmd_confirm_before_key_binding, NULL, @@ -52,9 +52,11 @@ cmd_confirm_before_key_binding(struct cmd *self, int key) switch (key) { case '&': self->args = args_create(1, "kill-window"); + args_set(self->args, 'p', "kill-window #W? (y/n)"); break; case 'x': self->args = args_create(1, "kill-pane"); + args_set(self->args, 'p', "kill-pane #P? (y/n)"); break; default: self->args = args_create(0); @@ -68,7 +70,8 @@ cmd_confirm_before_exec(struct cmd *self, struct cmd_ctx *ctx) struct args *args = self->args; struct cmd_confirm_before_data *cdata; struct client *c; - char *buf, *cmd, *ptr; + char *cmd, *copy, *new_prompt, *ptr; + const char *prompt; if (ctx->curclient == NULL) { ctx->error(ctx, "must be run interactively"); @@ -78,19 +81,23 @@ cmd_confirm_before_exec(struct cmd *self, struct cmd_ctx *ctx) if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL) return (-1); - ptr = xstrdup(args->argv[0]); - if ((cmd = strtok(ptr, " \t")) == NULL) - cmd = ptr; - xasprintf(&buf, "Confirm '%s'? (y/n) ", cmd); - xfree(ptr); + if ((prompt = args_get(args, 'p')) != NULL) + xasprintf(&new_prompt, "%s ", prompt); + else { + ptr = copy = xstrdup(args->argv[0]); + cmd = strsep(&ptr, " \t"); + xasprintf(&new_prompt, "Confirm '%s'? (y/n) ", cmd); + xfree(copy); + } cdata = xmalloc(sizeof *cdata); cdata->cmd = xstrdup(args->argv[0]); cdata->c = c; - status_prompt_set(cdata->c, buf, NULL, cmd_confirm_before_callback, - cmd_confirm_before_free, cdata, PROMPT_SINGLE); + status_prompt_set(cdata->c, new_prompt, NULL, + cmd_confirm_before_callback, cmd_confirm_before_free, cdata, + PROMPT_SINGLE); - xfree(buf); + xfree(new_prompt); return (1); } |