mirror of
https://github.com/tmux/tmux.git
synced 2025-01-07 16:28:48 +00:00
Make update-environment an array as well.
This commit is contained in:
parent
b77dd75b57
commit
4b2821ff98
@ -54,7 +54,6 @@ cmd_attach_session(struct cmdq_item *item, int dflag, int rflag,
|
|||||||
struct client *c = item->client, *c_loop;
|
struct client *c = item->client, *c_loop;
|
||||||
struct winlink *wl = item->state.tflag.wl;
|
struct winlink *wl = item->state.tflag.wl;
|
||||||
struct window_pane *wp = item->state.tflag.wp;
|
struct window_pane *wp = item->state.tflag.wp;
|
||||||
const char *update;
|
|
||||||
char *cause, *cwd;
|
char *cause, *cwd;
|
||||||
struct format_tree *ft;
|
struct format_tree *ft;
|
||||||
|
|
||||||
@ -95,12 +94,8 @@ cmd_attach_session(struct cmdq_item *item, int dflag, int rflag,
|
|||||||
server_client_detach(c_loop, MSG_DETACH);
|
server_client_detach(c_loop, MSG_DETACH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!Eflag)
|
||||||
if (!Eflag) {
|
environ_update(s->options, c->environ, s->environ);
|
||||||
update = options_get_string(s->options,
|
|
||||||
"update-environment");
|
|
||||||
environ_update(update, c->environ, s->environ);
|
|
||||||
}
|
|
||||||
|
|
||||||
c->session = s;
|
c->session = s;
|
||||||
server_client_set_key_table(c, NULL);
|
server_client_set_key_table(c, NULL);
|
||||||
@ -116,7 +111,6 @@ cmd_attach_session(struct cmdq_item *item, int dflag, int rflag,
|
|||||||
free(cause);
|
free(cause);
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rflag)
|
if (rflag)
|
||||||
c->flags |= CLIENT_READONLY;
|
c->flags |= CLIENT_READONLY;
|
||||||
|
|
||||||
@ -127,12 +121,8 @@ cmd_attach_session(struct cmdq_item *item, int dflag, int rflag,
|
|||||||
server_client_detach(c_loop, MSG_DETACH);
|
server_client_detach(c_loop, MSG_DETACH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!Eflag)
|
||||||
if (!Eflag) {
|
environ_update(s->options, c->environ, s->environ);
|
||||||
update = options_get_string(s->options,
|
|
||||||
"update-environment");
|
|
||||||
environ_update(update, c->environ, s->environ);
|
|
||||||
}
|
|
||||||
|
|
||||||
c->session = s;
|
c->session = s;
|
||||||
server_client_set_key_table(c, NULL);
|
server_client_set_key_table(c, NULL);
|
||||||
|
@ -73,7 +73,7 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
struct window *w;
|
struct window *w;
|
||||||
struct environ *env;
|
struct environ *env;
|
||||||
struct termios tio, *tiop;
|
struct termios tio, *tiop;
|
||||||
const char *newname, *target, *update, *errstr, *template;
|
const char *newname, *target, *errstr, *template;
|
||||||
const char *path, *cmd, *cwd, *to_free = NULL;
|
const char *path, *cmd, *cwd, *to_free = NULL;
|
||||||
char **argv, *cause, *cp;
|
char **argv, *cause, *cp;
|
||||||
int detached, already_attached, idx, argc;
|
int detached, already_attached, idx, argc;
|
||||||
@ -234,11 +234,8 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
|
|
||||||
/* Construct the environment. */
|
/* Construct the environment. */
|
||||||
env = environ_create();
|
env = environ_create();
|
||||||
if (c != NULL && !args_has(args, 'E')) {
|
if (c != NULL && !args_has(args, 'E'))
|
||||||
update = options_get_string(global_s_options,
|
environ_update(global_s_options, c->environ, env);
|
||||||
"update-environment");
|
|
||||||
environ_update(update, c->environ, env);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Create the new session. */
|
/* Create the new session. */
|
||||||
idx = -1 - options_get_number(global_s_options, "base-index");
|
idx = -1 - options_get_number(global_s_options, "base-index");
|
||||||
|
@ -53,7 +53,7 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
struct client *c = state->c;
|
struct client *c = state->c;
|
||||||
struct session *s = item->state.tflag.s;
|
struct session *s = item->state.tflag.s;
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
const char *tablename, *update;
|
const char *tablename;
|
||||||
struct key_table *table;
|
struct key_table *table;
|
||||||
|
|
||||||
if (args_has(args, 'r'))
|
if (args_has(args, 'r'))
|
||||||
@ -102,10 +102,8 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!args_has(args, 'E')) {
|
if (!args_has(args, 'E'))
|
||||||
update = options_get_string(s->options, "update-environment");
|
environ_update(s->options, c->environ, s->environ);
|
||||||
environ_update(update, c->environ, s->environ);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c->session != NULL && c->session != s)
|
if (c->session != NULL && c->session != s)
|
||||||
c->last_session = c->session;
|
c->last_session = c->session;
|
||||||
|
28
environ.c
28
environ.c
@ -169,25 +169,27 @@ environ_unset(struct environ *env, const char *name)
|
|||||||
free(envent);
|
free(envent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* Copy variables from a destination into a source * environment. */
|
||||||
* Copy a space-separated list of variables from a destination into a source
|
|
||||||
* environment.
|
|
||||||
*/
|
|
||||||
void
|
void
|
||||||
environ_update(const char *vars, struct environ *srcenv,
|
environ_update(struct options *oo, struct environ *src, struct environ *dst)
|
||||||
struct environ *dstenv)
|
|
||||||
{
|
{
|
||||||
struct environ_entry *envent;
|
struct environ_entry *envent;
|
||||||
char *copyvars, *var, *next;
|
struct options_entry *o;
|
||||||
|
u_int size, idx;
|
||||||
|
const char *value;
|
||||||
|
|
||||||
copyvars = next = xstrdup(vars);
|
o = options_get(oo, "update-environment");
|
||||||
while ((var = strsep(&next, " ")) != NULL) {
|
if (o == NULL || options_array_size(o, &size) == -1)
|
||||||
if ((envent = environ_find(srcenv, var)) == NULL)
|
return;
|
||||||
environ_clear(dstenv, var);
|
for (idx = 0; idx < size; idx++) {
|
||||||
|
value = options_array_get(o, idx);
|
||||||
|
if (value == NULL)
|
||||||
|
continue;
|
||||||
|
if ((envent = environ_find(src, value)) == NULL)
|
||||||
|
environ_clear(dst, value);
|
||||||
else
|
else
|
||||||
environ_set(dstenv, envent->name, "%s", envent->value);
|
environ_set(dst, envent->name, "%s", envent->value);
|
||||||
}
|
}
|
||||||
free(copyvars);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Push environment into the real environment - use after fork(). */
|
/* Push environment into the real environment - use after fork(). */
|
||||||
|
@ -482,11 +482,10 @@ const struct options_table_entry options_table[] = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
{ .name = "update-environment",
|
{ .name = "update-environment",
|
||||||
.type = OPTIONS_TABLE_STRING,
|
.type = OPTIONS_TABLE_ARRAY,
|
||||||
.scope = OPTIONS_TABLE_SESSION,
|
.scope = OPTIONS_TABLE_SESSION,
|
||||||
.default_str = "DISPLAY SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID "
|
.default_str = "DISPLAY SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID "
|
||||||
"SSH_CONNECTION WINDOWID XAUTHORITY"
|
"SSH_CONNECTION WINDOWID XAUTHORITY"
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
{ .name = "visual-activity",
|
{ .name = "visual-activity",
|
||||||
|
10
tmux.1
10
tmux.1
@ -2869,19 +2869,15 @@ For how to specify
|
|||||||
see the
|
see the
|
||||||
.Ic message-command-style
|
.Ic message-command-style
|
||||||
option.
|
option.
|
||||||
.It Ic update-environment Ar variables
|
.It Ic update-environment[] Ar variable
|
||||||
Set a space-separated string containing a list of environment variables to be
|
Set list of environment variables to be copied into the session environment
|
||||||
copied into the session environment when a new session is created or an
|
when a new session is created or an existing session is attached.
|
||||||
existing session is attached.
|
|
||||||
Any variables that do not exist in the source environment are set to be
|
Any variables that do not exist in the source environment are set to be
|
||||||
removed from the session environment (as if
|
removed from the session environment (as if
|
||||||
.Fl r
|
.Fl r
|
||||||
was given to the
|
was given to the
|
||||||
.Ic set-environment
|
.Ic set-environment
|
||||||
command).
|
command).
|
||||||
The default is
|
|
||||||
"DISPLAY SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION WINDOWID
|
|
||||||
XAUTHORITY".
|
|
||||||
.It Xo Ic visual-activity
|
.It Xo Ic visual-activity
|
||||||
.Op Ic on | off
|
.Op Ic on | off
|
||||||
.Xc
|
.Xc
|
||||||
|
2
tmux.h
2
tmux.h
@ -1669,7 +1669,7 @@ void printflike(3, 4) environ_set(struct environ *, const char *, const char *,
|
|||||||
void environ_clear(struct environ *, const char *);
|
void environ_clear(struct environ *, const char *);
|
||||||
void environ_put(struct environ *, const char *);
|
void environ_put(struct environ *, const char *);
|
||||||
void environ_unset(struct environ *, const char *);
|
void environ_unset(struct environ *, const char *);
|
||||||
void environ_update(const char *, struct environ *, struct environ *);
|
void environ_update(struct options *, struct environ *, struct environ *);
|
||||||
void environ_push(struct environ *);
|
void environ_push(struct environ *);
|
||||||
void environ_log(struct environ *, const char *);
|
void environ_log(struct environ *, const char *);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user