mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 00:56:10 +00:00 
			
		
		
		
	Sync OpenBSD patchset 934:
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.
			
			
This commit is contained in:
		@@ -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);
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										22
									
								
								status.c
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								status.c
									
									
									
									
									
								
							@@ -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;
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										13
									
								
								tmux.1
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								tmux.1
									
									
									
									
									
								
							@@ -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
 | 
			
		||||
@@ -2694,12 +2694,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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user