=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/cmd-set-environment.c,v retrieving revision 1.25 retrieving revision 1.26 diff -u -r1.25 -r1.26 --- src/usr.bin/tmux/cmd-set-environment.c 2020/04/13 10:59:58 1.25 +++ src/usr.bin/tmux/cmd-set-environment.c 2020/09/01 09:19:01 1.26 @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-set-environment.c,v 1.25 2020/04/13 10:59:58 nicm Exp $ */ +/* $OpenBSD: cmd-set-environment.c,v 1.26 2020/09/01 09:19:01 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -34,8 +34,8 @@ .name = "set-environment", .alias = "setenv", - .args = { "hgrt:u", 1, 2 }, - .usage = "[-hgru] " CMD_TARGET_SESSION_USAGE " name [value]", + .args = { "Fhgrt:u", 1, 2 }, + .usage = "[-Fhgru] " CMD_TARGET_SESSION_USAGE " name [value]", .target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL }, @@ -50,6 +50,8 @@ struct cmd_find_state *target = cmdq_get_target(item); struct environ *env; const char *name, *value, *tflag; + char *expand = NULL; + enum cmd_retval retval = CMD_RETURN_NORMAL; name = args->argv[0]; if (*name == '\0') { @@ -63,6 +65,8 @@ if (args->argc < 2) value = NULL; + else if (args_has(args, 'F')) + value = expand = format_single_from_target(item, args->argv[1]); else value = args->argv[1]; @@ -75,7 +79,8 @@ cmdq_error(item, "no such session: %s", tflag); else cmdq_error(item, "no current session"); - return (CMD_RETURN_ERROR); + retval = CMD_RETURN_ERROR; + goto out; } env = target->s->environ; } @@ -83,25 +88,31 @@ if (args_has(args, 'u')) { if (value != NULL) { cmdq_error(item, "can't specify a value with -u"); - return (CMD_RETURN_ERROR); + retval = CMD_RETURN_ERROR; + goto out; } environ_unset(env, name); } else if (args_has(args, 'r')) { if (value != NULL) { cmdq_error(item, "can't specify a value with -r"); - return (CMD_RETURN_ERROR); + retval = CMD_RETURN_ERROR; + goto out; } environ_clear(env, name); } else { if (value == NULL) { cmdq_error(item, "no value specified"); - return (CMD_RETURN_ERROR); + retval = CMD_RETURN_ERROR; + goto out; } + 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); +out: + free(expand); + return (retval); }