summaryrefslogtreecommitdiff
path: root/usr.bin/tmux/cmd-set-environment.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/tmux/cmd-set-environment.c')
-rw-r--r--usr.bin/tmux/cmd-set-environment.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/usr.bin/tmux/cmd-set-environment.c b/usr.bin/tmux/cmd-set-environment.c
index 22c24b56462..b039e7bbc71 100644
--- a/usr.bin/tmux/cmd-set-environment.c
+++ b/usr.bin/tmux/cmd-set-environment.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-set-environment.c,v 1.26 2020/09/01 09:19:01 nicm Exp $ */
+/* $OpenBSD: cmd-set-environment.c,v 1.27 2021/08/20 19:50:17 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -49,11 +49,11 @@ cmd_set_environment_exec(struct cmd *self, struct cmdq_item *item)
struct args *args = cmd_get_args(self);
struct cmd_find_state *target = cmdq_get_target(item);
struct environ *env;
- const char *name, *value, *tflag;
- char *expand = NULL;
+ const char *name = args_string(args, 0), *value;
+ const char *tflag;
+ char *expanded = NULL;
enum cmd_retval retval = CMD_RETURN_NORMAL;
- name = args->argv[0];
if (*name == '\0') {
cmdq_error(item, "empty variable name");
return (CMD_RETURN_ERROR);
@@ -63,13 +63,14 @@ cmd_set_environment_exec(struct cmd *self, struct cmdq_item *item)
return (CMD_RETURN_ERROR);
}
- if (args->argc < 2)
+ if (args_count(args) < 2)
value = NULL;
- else if (args_has(args, 'F'))
- value = expand = format_single_from_target(item, args->argv[1]);
else
- value = args->argv[1];
-
+ value = args_string(args, 1);
+ if (value != NULL && args_has(args, 'F')) {
+ expanded = format_single_from_target(item, value);
+ value = expanded;
+ }
if (args_has(args, 'g'))
env = global_environ;
else {
@@ -113,6 +114,6 @@ cmd_set_environment_exec(struct cmd *self, struct cmdq_item *item)
}
out:
- free(expand);
+ free(expanded);
return (retval);
}