aboutsummaryrefslogtreecommitdiff
path: root/cmd-set-environment.c
diff options
context:
space:
mode:
Diffstat (limited to 'cmd-set-environment.c')
-rw-r--r--cmd-set-environment.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/cmd-set-environment.c b/cmd-set-environment.c
index a80acd01..3c43b635 100644
--- a/cmd-set-environment.c
+++ b/cmd-set-environment.c
@@ -34,8 +34,8 @@ const struct cmd_entry cmd_set_environment_entry = {
.name = "set-environment",
.alias = "setenv",
- .args = { "grt:u", 1, 2 },
- .usage = "[-gru] " CMD_TARGET_SESSION_USAGE " name [value]",
+ .args = { "hgrt:u", 1, 2 },
+ .usage = "[-hgru] " CMD_TARGET_SESSION_USAGE " name [value]",
.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
@@ -46,9 +46,10 @@ const struct cmd_entry cmd_set_environment_entry = {
static enum cmd_retval
cmd_set_environment_exec(struct cmd *self, struct cmdq_item *item)
{
- struct args *args = self->args;
- struct environ *env;
- const char *name, *value, *target;
+ struct args *args = cmd_get_args(self);
+ struct cmd_find_state *target = cmdq_get_target(item);
+ struct environ *env;
+ const char *name, *value, *tflag;
name = args->argv[0];
if (*name == '\0') {
@@ -65,27 +66,27 @@ cmd_set_environment_exec(struct cmd *self, struct cmdq_item *item)
else
value = args->argv[1];
- if (args_has(self->args, 'g'))
+ if (args_has(args, 'g'))
env = global_environ;
else {
- if (item->target.s == NULL) {
- target = args_get(args, 't');
- if (target != NULL)
- cmdq_error(item, "no such session: %s", target);
+ if (target->s == NULL) {
+ tflag = args_get(args, 't');
+ if (tflag != NULL)
+ cmdq_error(item, "no such session: %s", tflag);
else
cmdq_error(item, "no current session");
return (CMD_RETURN_ERROR);
}
- env = item->target.s->environ;
+ env = target->s->environ;
}
- if (args_has(self->args, 'u')) {
+ if (args_has(args, 'u')) {
if (value != NULL) {
cmdq_error(item, "can't specify a value with -u");
return (CMD_RETURN_ERROR);
}
environ_unset(env, name);
- } else if (args_has(self->args, 'r')) {
+ } else if (args_has(args, 'r')) {
if (value != NULL) {
cmdq_error(item, "can't specify a value with -r");
return (CMD_RETURN_ERROR);
@@ -96,7 +97,10 @@ cmd_set_environment_exec(struct cmd *self, struct cmdq_item *item)
cmdq_error(item, "no value specified");
return (CMD_RETURN_ERROR);
}
- environ_set(env, name, "%s", value);
+ if (args_has(args, 'h'))
+ environ_set(env, name, ENVIRON_HIDDEN, "%s", value);
+ else
+ environ_set(env, name, 0, "%s", value);
}
return (CMD_RETURN_NORMAL);