mirror of
				https://github.com/tmux/tmux.git
				synced 2025-10-26 12:27:15 +00:00 
			
		
		
		
	Add -e flag to set environment for popup, from Alexis Hildebrandt in
GitHub issue 2924.
This commit is contained in:
		| @@ -53,10 +53,10 @@ const struct cmd_entry cmd_display_popup_entry = { | |||||||
| 	.name = "display-popup", | 	.name = "display-popup", | ||||||
| 	.alias = "popup", | 	.alias = "popup", | ||||||
|  |  | ||||||
| 	.args = { "BCc:d:Eh:t:w:x:y:", 0, -1, NULL }, | 	.args = { "BCc:d:e:Eh:t:w:x:y:", 0, -1, NULL }, | ||||||
| 	.usage = "[-BCE] [-c target-client] [-d start-directory] [-h height] " | 	.usage = "[-BCE] [-c target-client] [-d start-directory] " | ||||||
| 		 CMD_TARGET_PANE_USAGE " [-w width] " | 		 "[-e environment] [-h height] " CMD_TARGET_PANE_USAGE " " | ||||||
| 		 "[-x position] [-y position] [shell-command]", | 		 "[-w width] [-x position] [-y position] [shell-command]", | ||||||
|  |  | ||||||
| 	.target = { 't', CMD_FIND_PANE, 0 }, | 	.target = { 't', CMD_FIND_PANE, 0 }, | ||||||
|  |  | ||||||
| @@ -357,6 +357,8 @@ cmd_display_popup_exec(struct cmd *self, struct cmdq_item *item) | |||||||
| 	char			*cwd, *cause, **argv = NULL; | 	char			*cwd, *cause, **argv = NULL; | ||||||
| 	int			 flags = 0, argc = 0; | 	int			 flags = 0, argc = 0; | ||||||
| 	u_int			 px, py, w, h, count = args_count(args); | 	u_int			 px, py, w, h, count = args_count(args); | ||||||
|  | 	struct args_value	*av; | ||||||
|  | 	struct environ		*env = NULL; | ||||||
|  |  | ||||||
| 	if (args_has(args, 'C')) { | 	if (args_has(args, 'C')) { | ||||||
| 		server_client_clear_overlay(tc); | 		server_client_clear_overlay(tc); | ||||||
| @@ -410,17 +412,30 @@ cmd_display_popup_exec(struct cmd *self, struct cmdq_item *item) | |||||||
| 	} else | 	} else | ||||||
| 		args_to_vector(args, &argc, &argv); | 		args_to_vector(args, &argc, &argv); | ||||||
|  |  | ||||||
|  | 	if (args_has(args, 'e') >= 1) { | ||||||
|  | 		env = environ_create(); | ||||||
|  | 		av = args_first_value(args, 'e'); | ||||||
|  | 		while (av != NULL) { | ||||||
|  | 			environ_put(env, av->string, 0); | ||||||
|  | 			av = args_next_value(av); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	if (args_has(args, 'E') > 1) | 	if (args_has(args, 'E') > 1) | ||||||
| 		flags |= POPUP_CLOSEEXITZERO; | 		flags |= POPUP_CLOSEEXITZERO; | ||||||
| 	else if (args_has(args, 'E')) | 	else if (args_has(args, 'E')) | ||||||
| 		flags |= POPUP_CLOSEEXIT; | 		flags |= POPUP_CLOSEEXIT; | ||||||
| 	if (args_has(args, 'B')) | 	if (args_has(args, 'B')) | ||||||
| 		flags |= POPUP_NOBORDER; | 		flags |= POPUP_NOBORDER; | ||||||
| 	if (popup_display(flags, item, px, py, w, h, shellcmd, argc, argv, cwd, | 	if (popup_display(flags, item, px, py, w, h, env, shellcmd, argc, argv, | ||||||
| 	    tc, s, NULL, NULL) != 0) { | 	    cwd, tc, s, NULL, NULL) != 0) { | ||||||
| 		cmd_free_argv(argc, argv); | 		cmd_free_argv(argc, argv); | ||||||
|  | 		if (env != NULL) | ||||||
|  | 			environ_free(env); | ||||||
| 		return (CMD_RETURN_NORMAL); | 		return (CMD_RETURN_NORMAL); | ||||||
| 	} | 	} | ||||||
|  | 	if (env != NULL) | ||||||
|  | 		environ_free(env); | ||||||
| 	cmd_free_argv(argc, argv); | 	cmd_free_argv(argc, argv); | ||||||
| 	return (CMD_RETURN_WAIT); | 	return (CMD_RETURN_WAIT); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -118,7 +118,7 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item) | |||||||
| 	if (cdata->client != NULL) | 	if (cdata->client != NULL) | ||||||
| 		cdata->client->references++; | 		cdata->client->references++; | ||||||
|  |  | ||||||
| 	if (job_run(shellcmd, 0, NULL, s, | 	if (job_run(shellcmd, 0, NULL, NULL, s, | ||||||
| 	    server_client_get_cwd(cmdq_get_client(item), s), NULL, | 	    server_client_get_cwd(cmdq_get_client(item), s), NULL, | ||||||
| 	    cmd_if_shell_callback, cmd_if_shell_free, cdata, 0, -1, | 	    cmd_if_shell_callback, cmd_if_shell_free, cdata, 0, -1, | ||||||
| 	    -1) == NULL) { | 	    -1) == NULL) { | ||||||
|   | |||||||
| @@ -188,7 +188,7 @@ cmd_run_shell_timer(__unused int fd, __unused short events, void* arg) | |||||||
| 			cmd_run_shell_free(cdata); | 			cmd_run_shell_free(cdata); | ||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
| 		if (job_run(cmd, 0, NULL, cdata->s, cdata->cwd, NULL, | 		if (job_run(cmd, 0, NULL, NULL, cdata->s, cdata->cwd, NULL, | ||||||
| 		    cmd_run_shell_callback, cmd_run_shell_free, cdata, | 		    cmd_run_shell_callback, cmd_run_shell_free, cdata, | ||||||
| 		    cdata->flags, -1, -1) == NULL) | 		    cdata->flags, -1, -1) == NULL) | ||||||
| 			cmd_run_shell_free(cdata); | 			cmd_run_shell_free(cdata); | ||||||
|   | |||||||
							
								
								
									
										2
									
								
								format.c
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								format.c
									
									
									
									
									
								
							| @@ -390,7 +390,7 @@ format_job_get(struct format_expand_state *es, const char *cmd) | |||||||
| 	if (force && fj->job != NULL) | 	if (force && fj->job != NULL) | ||||||
| 	       job_free(fj->job); | 	       job_free(fj->job); | ||||||
| 	if (force || (fj->job == NULL && fj->last != t)) { | 	if (force || (fj->job == NULL && fj->last != t)) { | ||||||
| 		fj->job = job_run(expanded, 0, NULL, NULL, | 		fj->job = job_run(expanded, 0, NULL, NULL, NULL, | ||||||
| 		    server_client_get_cwd(ft->client, NULL), format_job_update, | 		    server_client_get_cwd(ft->client, NULL), format_job_update, | ||||||
| 		    format_job_complete, NULL, fj, JOB_NOWAIT, -1, -1); | 		    format_job_complete, NULL, fj, JOB_NOWAIT, -1, -1); | ||||||
| 		if (fj->job == NULL) { | 		if (fj->job == NULL) { | ||||||
|   | |||||||
							
								
								
									
										5
									
								
								job.c
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								job.c
									
									
									
									
									
								
							| @@ -71,7 +71,7 @@ static LIST_HEAD(joblist, job) all_jobs = LIST_HEAD_INITIALIZER(all_jobs); | |||||||
|  |  | ||||||
| /* Start a job running. */ | /* Start a job running. */ | ||||||
| struct job * | struct job * | ||||||
| job_run(const char *cmd, int argc, char **argv, struct session *s, | job_run(const char *cmd, int argc, char **argv, struct environ *e, struct session *s, | ||||||
|     const char *cwd, job_update_cb updatecb, job_complete_cb completecb, |     const char *cwd, job_update_cb updatecb, job_complete_cb completecb, | ||||||
|     job_free_cb freecb, void *data, int flags, int sx, int sy) |     job_free_cb freecb, void *data, int flags, int sx, int sy) | ||||||
| { | { | ||||||
| @@ -89,6 +89,9 @@ job_run(const char *cmd, int argc, char **argv, struct session *s, | |||||||
| 	 * if-shell to decide on default-terminal based on outside TERM. | 	 * if-shell to decide on default-terminal based on outside TERM. | ||||||
| 	 */ | 	 */ | ||||||
| 	env = environ_for_session(s, !cfg_finished); | 	env = environ_for_session(s, !cfg_finished); | ||||||
|  | 	if (e != NULL) { | ||||||
|  | 		environ_copy(e, env); | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	sigfillset(&set); | 	sigfillset(&set); | ||||||
| 	sigprocmask(SIG_BLOCK, &set, &oldset); | 	sigprocmask(SIG_BLOCK, &set, &oldset); | ||||||
|   | |||||||
							
								
								
									
										9
									
								
								popup.c
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								popup.c
									
									
									
									
									
								
							| @@ -590,8 +590,9 @@ popup_job_complete_cb(struct job *job) | |||||||
|  |  | ||||||
| int | int | ||||||
| popup_display(int flags, struct cmdq_item *item, u_int px, u_int py, u_int sx, | popup_display(int flags, struct cmdq_item *item, u_int px, u_int py, u_int sx, | ||||||
|     u_int sy, const char *shellcmd, int argc, char **argv, const char *cwd, |     u_int sy, struct environ *env, const char *shellcmd, int argc, char **argv, | ||||||
|     struct client *c, struct session *s, popup_close_cb cb, void *arg) |     const char *cwd, struct client *c, struct session *s, popup_close_cb cb, | ||||||
|  |     void *arg) | ||||||
| { | { | ||||||
| 	struct popup_data	*pd; | 	struct popup_data	*pd; | ||||||
| 	u_int			 jx, jy; | 	u_int			 jx, jy; | ||||||
| @@ -635,7 +636,7 @@ popup_display(int flags, struct cmdq_item *item, u_int px, u_int py, u_int sx, | |||||||
| 	pd->psx = sx; | 	pd->psx = sx; | ||||||
| 	pd->psy = sy; | 	pd->psy = sy; | ||||||
|  |  | ||||||
| 	pd->job = job_run(shellcmd, argc, argv, s, cwd, | 	pd->job = job_run(shellcmd, argc, argv, env, s, cwd, | ||||||
| 	    popup_job_update_cb, popup_job_complete_cb, NULL, pd, | 	    popup_job_update_cb, popup_job_complete_cb, NULL, pd, | ||||||
| 	    JOB_NOWAIT|JOB_PTY|JOB_KEEPWRITE, jx, jy); | 	    JOB_NOWAIT|JOB_PTY|JOB_KEEPWRITE, jx, jy); | ||||||
| 	pd->ictx = input_init(NULL, job_get_event(pd->job), &pd->palette); | 	pd->ictx = input_init(NULL, job_get_event(pd->job), &pd->palette); | ||||||
| @@ -725,7 +726,7 @@ popup_editor(struct client *c, const char *buf, size_t len, | |||||||
|  |  | ||||||
| 	xasprintf(&cmd, "%s %s", editor, path); | 	xasprintf(&cmd, "%s %s", editor, path); | ||||||
| 	if (popup_display(POPUP_INTERNAL|POPUP_CLOSEEXIT, NULL, px, py, sx, sy, | 	if (popup_display(POPUP_INTERNAL|POPUP_CLOSEEXIT, NULL, px, py, sx, sy, | ||||||
| 	    cmd, 0, NULL, _PATH_TMP, c, NULL, popup_editor_close_cb, pe) != 0) { | 	    NULL, cmd, 0, NULL, _PATH_TMP, c, NULL, popup_editor_close_cb, pe) != 0) { | ||||||
| 		popup_editor_free(pe); | 		popup_editor_free(pe); | ||||||
| 		free(cmd); | 		free(cmd); | ||||||
| 		return (-1); | 		return (-1); | ||||||
|   | |||||||
							
								
								
									
										7
									
								
								tmux.1
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								tmux.1
									
									
									
									
									
								
							| @@ -5753,6 +5753,7 @@ forwards any input read from stdin to the empty pane given by | |||||||
| .Op Fl BCE | .Op Fl BCE | ||||||
| .Op Fl c Ar target-client | .Op Fl c Ar target-client | ||||||
| .Op Fl d Ar start-directory | .Op Fl d Ar start-directory | ||||||
|  | .Op Fl e Ar environment | ||||||
| .Op Fl h Ar height | .Op Fl h Ar height | ||||||
| .Op Fl t Ar target-pane | .Op Fl t Ar target-pane | ||||||
| .Op Fl w Ar width | .Op Fl w Ar width | ||||||
| @@ -5793,6 +5794,12 @@ If omitted, half of the terminal size is used. | |||||||
| .Fl B | .Fl B | ||||||
| does not surround the popup by a border. | does not surround the popup by a border. | ||||||
| .Pp | .Pp | ||||||
|  | .Fl e | ||||||
|  | takes the form | ||||||
|  | .Ql VARIABLE=value | ||||||
|  | and sets an environment variable for the popup; it may be specified multiple | ||||||
|  | times. | ||||||
|  | .Pp | ||||||
| The | The | ||||||
| .Fl C | .Fl C | ||||||
| flag closes any popup on the client. | flag closes any popup on the client. | ||||||
|   | |||||||
							
								
								
									
										11
									
								
								tmux.h
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								tmux.h
									
									
									
									
									
								
							| @@ -2073,9 +2073,9 @@ typedef void (*job_free_cb) (void *); | |||||||
| #define JOB_NOWAIT 0x1 | #define JOB_NOWAIT 0x1 | ||||||
| #define JOB_KEEPWRITE 0x2 | #define JOB_KEEPWRITE 0x2 | ||||||
| #define JOB_PTY 0x4 | #define JOB_PTY 0x4 | ||||||
| struct job	*job_run(const char *, int, char **, struct session *, | struct job	*job_run(const char *, int, char **, struct environ *, | ||||||
| 		     const char *, job_update_cb, job_complete_cb, job_free_cb, | 		     struct session *, const char *, job_update_cb, | ||||||
| 		     void *, int, int, int); | 		     job_complete_cb, job_free_cb, void *, int, int, int); | ||||||
| void		 job_free(struct job *); | void		 job_free(struct job *); | ||||||
| int		 job_transfer(struct job *, pid_t *, char *, size_t); | int		 job_transfer(struct job *, pid_t *, char *, size_t); | ||||||
| void		 job_resize(struct job *, u_int, u_int); | void		 job_resize(struct job *, u_int, u_int); | ||||||
| @@ -3105,8 +3105,9 @@ int		 menu_key_cb(struct client *, void *, struct key_event *); | |||||||
| typedef void (*popup_close_cb)(int, void *); | typedef void (*popup_close_cb)(int, void *); | ||||||
| typedef void (*popup_finish_edit_cb)(char *, size_t, void *); | typedef void (*popup_finish_edit_cb)(char *, size_t, void *); | ||||||
| int		 popup_display(int, struct cmdq_item *, u_int, u_int, u_int, | int		 popup_display(int, struct cmdq_item *, u_int, u_int, u_int, | ||||||
| 		    u_int, const char *, int, char **, const char *, | 		    u_int, struct environ *, const char *, int, char **, | ||||||
| 		    struct client *, struct session *, popup_close_cb, void *); | 		    const char *, struct client *, struct session *, | ||||||
|  | 		    popup_close_cb, void *); | ||||||
| int		 popup_editor(struct client *, const char *, size_t, | int		 popup_editor(struct client *, const char *, size_t, | ||||||
| 		    popup_finish_edit_cb, void *); | 		    popup_finish_edit_cb, void *); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -4531,8 +4531,8 @@ window_copy_pipe_run(struct window_mode_entry *wme, struct session *s, | |||||||
| 	if (cmd == NULL || *cmd == '\0') | 	if (cmd == NULL || *cmd == '\0') | ||||||
| 		cmd = options_get_string(global_options, "copy-command"); | 		cmd = options_get_string(global_options, "copy-command"); | ||||||
| 	if (cmd != NULL && *cmd != '\0') { | 	if (cmd != NULL && *cmd != '\0') { | ||||||
| 		job = job_run(cmd, 0, NULL, s, NULL, NULL, NULL, NULL, NULL, | 		job = job_run(cmd, 0, NULL, NULL, s, NULL, NULL, NULL, NULL, | ||||||
| 		    JOB_NOWAIT, -1, -1); | 		    NULL, JOB_NOWAIT, -1, -1); | ||||||
| 		bufferevent_write(job_get_event(job), buf, *len); | 		bufferevent_write(job_get_event(job), buf, *len); | ||||||
| 	} | 	} | ||||||
| 	return (buf); | 	return (buf); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 nicm
					nicm