mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 00:56:10 +00:00 
			
		
		
		
	Sync OpenBSD patchset 820:
Add a -P option to new-window and split-window to print the new window or pane index in target form (useful to pass it into other commands).
This commit is contained in:
		@@ -1,4 +1,4 @@
 | 
				
			|||||||
/* $Id: cmd-new-window.c,v 1.47 2010-07-02 02:49:19 tcunha Exp $ */
 | 
					/* $Id: cmd-new-window.c,v 1.48 2011-01-03 23:29:09 tcunha Exp $ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
					 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
				
			||||||
@@ -39,11 +39,12 @@ struct cmd_new_window_data {
 | 
				
			|||||||
	int	 flag_insert_after;
 | 
						int	 flag_insert_after;
 | 
				
			||||||
	int	 flag_detached;
 | 
						int	 flag_detached;
 | 
				
			||||||
	int	 flag_kill;
 | 
						int	 flag_kill;
 | 
				
			||||||
 | 
						int      flag_print;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const struct cmd_entry cmd_new_window_entry = {
 | 
					const struct cmd_entry cmd_new_window_entry = {
 | 
				
			||||||
	"new-window", "neww",
 | 
						"new-window", "neww",
 | 
				
			||||||
	"[-adk] [-n window-name] [-t target-window] [command]",
 | 
						"[-adkP] [-n window-name] [-t target-window] [command]",
 | 
				
			||||||
	0, "",
 | 
						0, "",
 | 
				
			||||||
	cmd_new_window_init,
 | 
						cmd_new_window_init,
 | 
				
			||||||
	cmd_new_window_parse,
 | 
						cmd_new_window_parse,
 | 
				
			||||||
@@ -65,6 +66,7 @@ cmd_new_window_init(struct cmd *self, unused int arg)
 | 
				
			|||||||
	data->flag_insert_after = 0;
 | 
						data->flag_insert_after = 0;
 | 
				
			||||||
	data->flag_detached = 0;
 | 
						data->flag_detached = 0;
 | 
				
			||||||
	data->flag_kill = 0;
 | 
						data->flag_kill = 0;
 | 
				
			||||||
 | 
						data->flag_print = 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int
 | 
					int
 | 
				
			||||||
@@ -76,7 +78,7 @@ cmd_new_window_parse(struct cmd *self, int argc, char **argv, char **cause)
 | 
				
			|||||||
	self->entry->init(self, KEYC_NONE);
 | 
						self->entry->init(self, KEYC_NONE);
 | 
				
			||||||
	data = self->data;
 | 
						data = self->data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	while ((opt = getopt(argc, argv, "adkt:n:")) != -1) {
 | 
						while ((opt = getopt(argc, argv, "adkt:n:P")) != -1) {
 | 
				
			||||||
		switch (opt) {
 | 
							switch (opt) {
 | 
				
			||||||
		case 'a':
 | 
							case 'a':
 | 
				
			||||||
			data->flag_insert_after = 1;
 | 
								data->flag_insert_after = 1;
 | 
				
			||||||
@@ -95,6 +97,9 @@ cmd_new_window_parse(struct cmd *self, int argc, char **argv, char **cause)
 | 
				
			|||||||
			if (data->name == NULL)
 | 
								if (data->name == NULL)
 | 
				
			||||||
				data->name = xstrdup(optarg);
 | 
									data->name = xstrdup(optarg);
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
 | 
							case 'P':
 | 
				
			||||||
 | 
								data->flag_print = 1;
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
		default:
 | 
							default:
 | 
				
			||||||
			goto usage;
 | 
								goto usage;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -198,6 +203,8 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
 | 
				
			|||||||
	} else
 | 
						} else
 | 
				
			||||||
		server_status_session_group(s);
 | 
							server_status_session_group(s);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (data->flag_print)
 | 
				
			||||||
 | 
							ctx->print(ctx, "%s:%u", s->name, wl->idx);
 | 
				
			||||||
	return (0);
 | 
						return (0);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -226,6 +233,8 @@ cmd_new_window_print(struct cmd *self, char *buf, size_t len)
 | 
				
			|||||||
		return (off);
 | 
							return (off);
 | 
				
			||||||
	if (off < len && data->flag_detached)
 | 
						if (off < len && data->flag_detached)
 | 
				
			||||||
		off += xsnprintf(buf + off, len - off, " -d");
 | 
							off += xsnprintf(buf + off, len - off, " -d");
 | 
				
			||||||
 | 
						if (off < len && data->flag_print)
 | 
				
			||||||
 | 
							off += xsnprintf(buf + off, len - off, " -P");
 | 
				
			||||||
	if (off < len && data->target != NULL)
 | 
						if (off < len && data->target != NULL)
 | 
				
			||||||
		off += cmd_prarg(buf + off, len - off, " -t ", data->target);
 | 
							off += cmd_prarg(buf + off, len - off, " -t ", data->target);
 | 
				
			||||||
	if (off < len && data->name != NULL)
 | 
						if (off < len && data->name != NULL)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
/* $Id: cmd-split-window.c,v 1.35 2010-07-02 02:49:19 tcunha Exp $ */
 | 
					/* $Id: cmd-split-window.c,v 1.36 2011-01-03 23:29:09 tcunha Exp $ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
					 * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
				
			||||||
@@ -38,13 +38,14 @@ struct cmd_split_window_data {
 | 
				
			|||||||
	char	*cmd;
 | 
						char	*cmd;
 | 
				
			||||||
	int	 flag_detached;
 | 
						int	 flag_detached;
 | 
				
			||||||
	int	 flag_horizontal;
 | 
						int	 flag_horizontal;
 | 
				
			||||||
 | 
						int	 flag_print;
 | 
				
			||||||
	int	 percentage;
 | 
						int	 percentage;
 | 
				
			||||||
	int	 size;
 | 
						int	 size;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const struct cmd_entry cmd_split_window_entry = {
 | 
					const struct cmd_entry cmd_split_window_entry = {
 | 
				
			||||||
	"split-window", "splitw",
 | 
						"split-window", "splitw",
 | 
				
			||||||
	"[-dhv] [-p percentage|-l size] [-t target-pane] [command]",
 | 
						"[-dhvP] [-p percentage|-l size] [-t target-pane] [command]",
 | 
				
			||||||
	0, "",
 | 
						0, "",
 | 
				
			||||||
	cmd_split_window_init,
 | 
						cmd_split_window_init,
 | 
				
			||||||
	cmd_split_window_parse,
 | 
						cmd_split_window_parse,
 | 
				
			||||||
@@ -63,6 +64,7 @@ cmd_split_window_init(struct cmd *self, int key)
 | 
				
			|||||||
	data->cmd = NULL;
 | 
						data->cmd = NULL;
 | 
				
			||||||
	data->flag_detached = 0;
 | 
						data->flag_detached = 0;
 | 
				
			||||||
	data->flag_horizontal = 0;
 | 
						data->flag_horizontal = 0;
 | 
				
			||||||
 | 
						data->flag_print = 0;
 | 
				
			||||||
	data->percentage = -1;
 | 
						data->percentage = -1;
 | 
				
			||||||
	data->size = -1;
 | 
						data->size = -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -86,7 +88,7 @@ cmd_split_window_parse(struct cmd *self, int argc, char **argv, char **cause)
 | 
				
			|||||||
	self->entry->init(self, KEYC_NONE);
 | 
						self->entry->init(self, KEYC_NONE);
 | 
				
			||||||
	data = self->data;
 | 
						data = self->data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	while ((opt = getopt(argc, argv, "dhl:p:t:v")) != -1) {
 | 
						while ((opt = getopt(argc, argv, "dhl:p:Pt:v")) != -1) {
 | 
				
			||||||
		switch (opt) {
 | 
							switch (opt) {
 | 
				
			||||||
		case 'd':
 | 
							case 'd':
 | 
				
			||||||
			data->flag_detached = 1;
 | 
								data->flag_detached = 1;
 | 
				
			||||||
@@ -116,6 +118,9 @@ cmd_split_window_parse(struct cmd *self, int argc, char **argv, char **cause)
 | 
				
			|||||||
				goto error;
 | 
									goto error;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
 | 
							case 'P':
 | 
				
			||||||
 | 
								data->flag_print = 1;
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
		case 'v':
 | 
							case 'v':
 | 
				
			||||||
			data->flag_horizontal = 0;
 | 
								data->flag_horizontal = 0;
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
@@ -152,7 +157,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
 | 
				
			|||||||
	struct environ			 env;
 | 
						struct environ			 env;
 | 
				
			||||||
	char		 		*cmd, *cwd, *cause;
 | 
						char		 		*cmd, *cwd, *cause;
 | 
				
			||||||
	const char			*shell;
 | 
						const char			*shell;
 | 
				
			||||||
	u_int				 hlimit;
 | 
						u_int				 hlimit, paneidx;
 | 
				
			||||||
	int				 size;
 | 
						int				 size;
 | 
				
			||||||
	enum layout_type		 type;
 | 
						enum layout_type		 type;
 | 
				
			||||||
	struct layout_cell		*lc;
 | 
						struct layout_cell		*lc;
 | 
				
			||||||
@@ -216,6 +221,11 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
 | 
				
			|||||||
		server_status_session(s);
 | 
							server_status_session(s);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	environ_free(&env);
 | 
						environ_free(&env);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (data->flag_print) {
 | 
				
			||||||
 | 
							paneidx = window_pane_index(wl->window, new_wp);
 | 
				
			||||||
 | 
							ctx->print(ctx, "%s:%u.%u", s->name, wl->idx, paneidx);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	return (0);
 | 
						return (0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
error:
 | 
					error:
 | 
				
			||||||
@@ -252,6 +262,8 @@ cmd_split_window_print(struct cmd *self, char *buf, size_t len)
 | 
				
			|||||||
		off += xsnprintf(buf + off, len - off, " -d");
 | 
							off += xsnprintf(buf + off, len - off, " -d");
 | 
				
			||||||
	if (off < len && data->flag_horizontal)
 | 
						if (off < len && data->flag_horizontal)
 | 
				
			||||||
		off += xsnprintf(buf + off, len - off, " -h");
 | 
							off += xsnprintf(buf + off, len - off, " -h");
 | 
				
			||||||
 | 
						if (off < len && data->flag_print)
 | 
				
			||||||
 | 
							off += xsnprintf(buf + off, len - off, " -P");
 | 
				
			||||||
	if (off < len && data->size > 0)
 | 
						if (off < len && data->size > 0)
 | 
				
			||||||
		off += xsnprintf(buf + off, len - off, " -l %d", data->size);
 | 
							off += xsnprintf(buf + off, len - off, " -l %d", data->size);
 | 
				
			||||||
	if (off < len && data->percentage > 0) {
 | 
						if (off < len && data->percentage > 0) {
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										10
									
								
								tmux.1
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								tmux.1
									
									
									
									
									
								
							@@ -1,4 +1,4 @@
 | 
				
			|||||||
.\" $Id: tmux.1,v 1.283 2010-12-31 02:00:30 tcunha Exp $
 | 
					.\" $Id: tmux.1,v 1.284 2011-01-03 23:29:09 tcunha Exp $
 | 
				
			||||||
.\"
 | 
					.\"
 | 
				
			||||||
.\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
					.\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
				
			||||||
.\"
 | 
					.\"
 | 
				
			||||||
@@ -1101,7 +1101,7 @@ except the window at
 | 
				
			|||||||
is moved to
 | 
					is moved to
 | 
				
			||||||
.Ar dst-window .
 | 
					.Ar dst-window .
 | 
				
			||||||
.It Xo Ic new-window
 | 
					.It Xo Ic new-window
 | 
				
			||||||
.Op Fl adk
 | 
					.Op Fl adkP
 | 
				
			||||||
.Op Fl n Ar window-name
 | 
					.Op Fl n Ar window-name
 | 
				
			||||||
.Op Fl t Ar target-window
 | 
					.Op Fl t Ar target-window
 | 
				
			||||||
.Op Ar shell-command
 | 
					.Op Ar shell-command
 | 
				
			||||||
@@ -1149,6 +1149,10 @@ New windows will automatically have
 | 
				
			|||||||
.Dq TERM=screen
 | 
					.Dq TERM=screen
 | 
				
			||||||
added to their environment, but care must be taken not to reset this in shell
 | 
					added to their environment, but care must be taken not to reset this in shell
 | 
				
			||||||
start-up files.
 | 
					start-up files.
 | 
				
			||||||
 | 
					.Pp
 | 
				
			||||||
 | 
					The
 | 
				
			||||||
 | 
					.Fl P
 | 
				
			||||||
 | 
					option prints the location of the new window after it has been created.
 | 
				
			||||||
.It Ic next-layout Op Fl t Ar target-window
 | 
					.It Ic next-layout Op Fl t Ar target-window
 | 
				
			||||||
.D1 (alias: Ic nextl )
 | 
					.D1 (alias: Ic nextl )
 | 
				
			||||||
Move a window to the next layout and rearrange the panes to fit.
 | 
					Move a window to the next layout and rearrange the panes to fit.
 | 
				
			||||||
@@ -1285,7 +1289,7 @@ target pane is used.
 | 
				
			|||||||
Select the window at
 | 
					Select the window at
 | 
				
			||||||
.Ar target-window .
 | 
					.Ar target-window .
 | 
				
			||||||
.It Xo Ic split-window
 | 
					.It Xo Ic split-window
 | 
				
			||||||
.Op Fl dhv
 | 
					.Op Fl dhvP
 | 
				
			||||||
.Oo Fl l
 | 
					.Oo Fl l
 | 
				
			||||||
.Ar size |
 | 
					.Ar size |
 | 
				
			||||||
.Fl p Ar percentage Oc
 | 
					.Fl p Ar percentage Oc
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user