summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2011-07-08 06:37:58 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2011-07-08 06:37:58 +0000
commit12ceae2169c5fde32b67403312ac416dc4a2f577 (patch)
tree9c5329d0ef3b160e174ecf0574ad5cfa025ecd82
parentc6f9982ea401963ae1092e0af8c210975bd9e0f8 (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.
-rw-r--r--usr.bin/tmux/cmd-command-prompt.c41
-rw-r--r--usr.bin/tmux/cmd-confirm-before.c31
-rw-r--r--usr.bin/tmux/status.c24
-rw-r--r--usr.bin/tmux/tmux.115
4 files changed, 54 insertions, 57 deletions
diff --git a/usr.bin/tmux/cmd-command-prompt.c b/usr.bin/tmux/cmd-command-prompt.c
index 08cfa457081..7db34aafb1f 100644
--- a/usr.bin/tmux/cmd-command-prompt.c
+++ b/usr.bin/tmux/cmd-command-prompt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-command-prompt.c,v 1.18 2011/07/03 18:18:15 nicm Exp $ */
+/* $OpenBSD: cmd-command-prompt.c,v 1.19 2011/07/08 06:37:57 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -90,8 +90,7 @@ cmd_command_prompt_exec(struct cmd *self, struct cmd_ctx *ctx)
const char *inputs, *prompts;
struct cmd_command_prompt_cdata *cdata;
struct client *c;
- char *input = NULL;
- char *prompt, *prompt_replaced, *ptr;
+ char *prompt, *ptr, *input = NULL;
size_t n;
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
@@ -127,28 +126,18 @@ cmd_command_prompt_exec(struct cmd *self, struct cmd_ctx *ctx)
ptr = strsep(&cdata->next_prompt, ",");
if (prompts == NULL)
prompt = xstrdup(ptr);
- else {
- prompt_replaced = status_replace(c, NULL, NULL, NULL, ptr,
- time(NULL), 0);
- xasprintf(&prompt, "%s ", prompt_replaced);
- xfree(prompt_replaced);
- }
+ else
+ xasprintf(&prompt, "%s ", ptr);
/* Get initial prompt input. */
if ((inputs = args_get(args, 'I')) != NULL) {
cdata->inputs = xstrdup(inputs);
cdata->next_input = cdata->inputs;
- ptr = strsep(&cdata->next_input, ",");
-
- input = status_replace(c, NULL, NULL, NULL, ptr, time(NULL),
- 0);
+ input = strsep(&cdata->next_input, ",");
}
status_prompt_set(c, prompt, input, cmd_command_prompt_callback,
cmd_command_prompt_free, cdata, 0);
-
- if (input != NULL)
- xfree(input);
xfree(prompt);
return (0);
@@ -161,8 +150,8 @@ cmd_command_prompt_callback(void *data, const char *s)
struct client *c = cdata->c;
struct cmd_list *cmdlist;
struct cmd_ctx ctx;
- char *cause, *new_template, *prompt;
- char *prompt_replaced, *ptr, *input = NULL;
+ char *cause, *new_template, *prompt, *ptr;
+ char *input = NULL;
if (s == NULL)
return (0);
@@ -176,23 +165,11 @@ cmd_command_prompt_callback(void *data, const char *s)
* and update the prompt data.
*/
if ((ptr = strsep(&cdata->next_prompt, ",")) != NULL) {
- prompt_replaced = status_replace(c, NULL, NULL, NULL, ptr,
- time(NULL), 0);
- xasprintf(&prompt, "%s ", prompt_replaced);
-
- /* Find next input and expand special sequences. */
- if ((ptr = strsep(&cdata->next_input, ",")) != NULL) {
- input = status_replace(c, NULL, NULL, NULL, ptr,
- time(NULL), 0);
- }
-
+ xasprintf(&prompt, "%s ", ptr);
+ input = strsep(&cdata->next_input, ",");
status_prompt_update(c, prompt, input);
- if (input != NULL)
- xfree(input);
- xfree(prompt_replaced);
xfree(prompt);
-
cdata->idx++;
return (1);
}
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);
}
diff --git a/usr.bin/tmux/status.c b/usr.bin/tmux/status.c
index f8f9145d6c4..e96200331ef 100644
--- a/usr.bin/tmux/status.c
+++ b/usr.bin/tmux/status.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: status.c,v 1.76 2011/07/02 21:05:44 nicm Exp $ */
+/* $OpenBSD: status.c,v 1.77 2011/07/08 06:37:57 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -824,12 +824,13 @@ status_prompt_set(struct client *c, const char *msg, const char *input,
status_message_clear(c);
status_prompt_clear(c);
- c->prompt_string = xstrdup(msg);
+ c->prompt_string = status_replace(c, NULL, NULL, NULL, msg,
+ time(NULL), 0);
- if (input != NULL)
- c->prompt_buffer = xstrdup(input);
- else
- c->prompt_buffer = xstrdup("");
+ if (input == NULL)
+ input = "";
+ c->prompt_buffer = status_replace(c, NULL, NULL, NULL, input,
+ time(NULL), 0);
c->prompt_index = strlen(c->prompt_buffer);
c->prompt_callbackfn = callbackfn;
@@ -877,13 +878,14 @@ void
status_prompt_update(struct client *c, const char *msg, const char *input)
{
xfree(c->prompt_string);
- c->prompt_string = xstrdup(msg);
+ c->prompt_string = status_replace(c, NULL, NULL, NULL, msg,
+ time(NULL), 0);
xfree(c->prompt_buffer);
- if (input != NULL)
- c->prompt_buffer = xstrdup(input);
- else
- c->prompt_buffer = xstrdup("");
+ if (input == NULL)
+ input = "";
+ c->prompt_buffer = status_replace(c, NULL, NULL, NULL, input,
+ time(NULL), 0);
c->prompt_index = strlen(c->prompt_buffer);
c->prompt_hindex = 0;
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index 9fa27a66070..1ff28279855 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.237 2011/07/03 19:07:54 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.238 2011/07/08 06:37:57 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
.\"
@@ -14,7 +14,7 @@
.\" 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: July 3 2011 $
+.Dd $Mdocdate: July 8 2011 $
.Dt TMUX 1
.Os
.Sh NAME
@@ -2690,12 +2690,23 @@ to
.Ql %9
.Pc .
.It Xo Ic confirm-before
+.Op Fl p Ar prompt
.Op Fl t Ar target-client
.Ar command
.Xc
.D1 (alias: Ic confirm )
Ask for confirmation before executing
.Ar command .
+If
+.Fl p
+is given,
+.Ar prompt
+is the prompt to display; otherwise a prompt is constructed from
+.Ar command .
+It may contain the special character sequences supported by the
+.Ic status-left
+option.
+.Pp
This command works only from inside
.Nm .
.It Xo Ic display-message