summaryrefslogtreecommitdiffstats
path: root/cmd-confirm-before.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2011-07-08 06:37:57 +0000
committerNicholas Marriott <nicm@openbsd.org>2011-07-08 06:37:57 +0000
commit2de9b1e005be97c6f1acdd6e24803e01badff52c (patch)
tree50089173bc2ec9010ee0027672c7290c0d26890f /cmd-confirm-before.c
parentb4b3d9c936b9e22eb835dd1d8b65e689fc66fb6c (diff)
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 'cmd-confirm-before.c')
-rw-r--r--cmd-confirm-before.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/cmd-confirm-before.c b/cmd-confirm-before.c
index 958453e2..048465da 100644
--- a/cmd-confirm-before.c
+++ b/cmd-confirm-before.c
@@ -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);
}