mirror of
https://github.com/tmux/tmux.git
synced 2025-09-01 20:57:00 +00:00
Add a way to mark environment variables as "hidden" so they can be used
by tmux but are not passed into the environment of new panes.
This commit is contained in:
29
environ.c
29
environ.c
@ -86,8 +86,10 @@ environ_copy(struct environ *srcenv, struct environ *dstenv)
|
||||
RB_FOREACH(envent, environ, srcenv) {
|
||||
if (envent->value == NULL)
|
||||
environ_clear(dstenv, envent->name);
|
||||
else
|
||||
environ_set(dstenv, envent->name, "%s", envent->value);
|
||||
else {
|
||||
environ_set(dstenv, envent->name, envent->flags,
|
||||
"%s", envent->value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -103,18 +105,21 @@ environ_find(struct environ *env, const char *name)
|
||||
|
||||
/* Set an environment variable. */
|
||||
void
|
||||
environ_set(struct environ *env, const char *name, const char *fmt, ...)
|
||||
environ_set(struct environ *env, const char *name, int flags, const char *fmt,
|
||||
...)
|
||||
{
|
||||
struct environ_entry *envent;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
if ((envent = environ_find(env, name)) != NULL) {
|
||||
envent->flags = flags;
|
||||
free(envent->value);
|
||||
xvasprintf(&envent->value, fmt, ap);
|
||||
} else {
|
||||
envent = xmalloc(sizeof *envent);
|
||||
envent->name = xstrdup(name);
|
||||
envent->flags = flags;
|
||||
xvasprintf(&envent->value, fmt, ap);
|
||||
RB_INSERT(environ, env, envent);
|
||||
}
|
||||
@ -133,6 +138,7 @@ environ_clear(struct environ *env, const char *name)
|
||||
} else {
|
||||
envent = xmalloc(sizeof *envent);
|
||||
envent->name = xstrdup(name);
|
||||
envent->flags = 0;
|
||||
envent->value = NULL;
|
||||
RB_INSERT(environ, env, envent);
|
||||
}
|
||||
@ -140,7 +146,7 @@ environ_clear(struct environ *env, const char *name)
|
||||
|
||||
/* Set an environment variable from a NAME=VALUE string. */
|
||||
void
|
||||
environ_put(struct environ *env, const char *var)
|
||||
environ_put(struct environ *env, const char *var, int flags)
|
||||
{
|
||||
char *name, *value;
|
||||
|
||||
@ -152,7 +158,7 @@ environ_put(struct environ *env, const char *var)
|
||||
name = xstrdup(var);
|
||||
name[strcspn(name, "=")] = '\0';
|
||||
|
||||
environ_set(env, name, "%s", value);
|
||||
environ_set(env, name, flags, "%s", value);
|
||||
free(name);
|
||||
}
|
||||
|
||||
@ -170,7 +176,7 @@ environ_unset(struct environ *env, const char *name)
|
||||
free(envent);
|
||||
}
|
||||
|
||||
/* Copy variables from a destination into a source * environment. */
|
||||
/* Copy variables from a destination into a source environment. */
|
||||
void
|
||||
environ_update(struct options *oo, struct environ *src, struct environ *dst)
|
||||
{
|
||||
@ -188,7 +194,7 @@ environ_update(struct options *oo, struct environ *src, struct environ *dst)
|
||||
if ((envent = environ_find(src, ov->string)) == NULL)
|
||||
environ_clear(dst, ov->string);
|
||||
else
|
||||
environ_set(dst, envent->name, "%s", envent->value);
|
||||
environ_set(dst, envent->name, 0, "%s", envent->value);
|
||||
a = options_array_next(a);
|
||||
}
|
||||
}
|
||||
@ -201,7 +207,9 @@ environ_push(struct environ *env)
|
||||
|
||||
environ = xcalloc(1, sizeof *environ);
|
||||
RB_FOREACH(envent, environ, env) {
|
||||
if (envent->value != NULL && *envent->name != '\0')
|
||||
if (envent->value != NULL &&
|
||||
*envent->name != '\0' &&
|
||||
(~envent->flags & ENVIRON_HIDDEN))
|
||||
setenv(envent->name, envent->value, 1);
|
||||
}
|
||||
}
|
||||
@ -243,14 +251,15 @@ environ_for_session(struct session *s, int no_TERM)
|
||||
|
||||
if (!no_TERM) {
|
||||
value = options_get_string(global_options, "default-terminal");
|
||||
environ_set(env, "TERM", "%s", value);
|
||||
environ_set(env, "TERM", 0, "%s", value);
|
||||
}
|
||||
|
||||
if (s != NULL)
|
||||
idx = s->id;
|
||||
else
|
||||
idx = -1;
|
||||
environ_set(env, "TMUX", "%s,%ld,%d", socket_path, (long)getpid(), idx);
|
||||
environ_set(env, "TMUX", 0, "%s,%ld,%d", socket_path, (long)getpid(),
|
||||
idx);
|
||||
|
||||
return (env);
|
||||
}
|
||||
|
Reference in New Issue
Block a user