aboutsummaryrefslogtreecommitdiff
path: root/cmd-new-session.c
diff options
context:
space:
mode:
Diffstat (limited to 'cmd-new-session.c')
-rw-r--r--cmd-new-session.c53
1 files changed, 27 insertions, 26 deletions
diff --git a/cmd-new-session.c b/cmd-new-session.c
index 353f7bed..a9a0376b 100644
--- a/cmd-new-session.c
+++ b/cmd-new-session.c
@@ -39,10 +39,10 @@ const struct cmd_entry cmd_new_session_entry = {
.name = "new-session",
.alias = "new",
- .args = { "Ac:dDEF:n:Ps:t:x:Xy:", 0, -1 },
- .usage = "[-AdDEPX] [-c start-directory] [-F format] [-n window-name] "
- "[-s session-name] " CMD_TARGET_SESSION_USAGE " [-x width] "
- "[-y height] [command]",
+ .args = { "Ac:dDe:EF:f:n:Ps:t:x:Xy:", 0, -1 },
+ .usage = "[-AdDEPX] [-c start-directory] [-e environment] [-F format] "
+ "[-f flags] [-n window-name] [-s session-name] "
+ CMD_TARGET_SESSION_USAGE " [-x width] [-y height] [command]",
.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
@@ -70,18 +70,20 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
struct cmd_find_state *current = cmdq_get_current(item);
struct cmd_find_state *target = cmdq_get_target(item);
struct client *c = cmdq_get_client(item);
- struct session *s, *as, *groupwith;
+ struct session *s, *as, *groupwith = NULL;
struct environ *env;
struct options *oo;
struct termios tio, *tiop;
- struct session_group *sg;
- const char *errstr, *template, *group, *prefix, *tmp;
+ struct session_group *sg = NULL;
+ const char *errstr, *template, *group, *tmp, *add;
char *cause, *cwd = NULL, *cp, *newname = NULL;
+ char *name, *prefix = NULL;
int detached, already_attached, is_control = 0;
u_int sx, sy, dsx, dsy;
struct spawn_context sc;
enum cmd_retval retval;
struct cmd_find_state fs;
+ struct args_value *value;
if (cmd_get_entry(self) == &cmd_has_session_entry) {
/*
@@ -98,11 +100,9 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
tmp = args_get(args, 's');
if (tmp != NULL) {
- newname = format_single(item, tmp, c, NULL, NULL, NULL);
- if (!session_check_name(newname)) {
- cmdq_error(item, "bad session name: %s", newname);
- goto fail;
- }
+ name = format_single(item, tmp, c, NULL, NULL, NULL);
+ newname = session_check_name(name);
+ free(name);
}
if (args_has(args, 'A')) {
if (newname != NULL)
@@ -112,7 +112,7 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
if (as != NULL) {
retval = cmd_attach_session(item, as->name,
args_has(args, 'D'), args_has(args, 'X'), 0, NULL,
- args_has(args, 'E'));
+ args_has(args, 'E'), args_get(args, 'f'));
free(newname);
return (retval);
}
@@ -126,24 +126,16 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
group = args_get(args, 't');
if (group != NULL) {
groupwith = target->s;
- if (groupwith == NULL) {
- if (!session_check_name(group)) {
- cmdq_error(item, "bad group name: %s", group);
- goto fail;
- }
+ if (groupwith == NULL)
sg = session_group_find(group);
- } else
+ else
sg = session_group_contains(groupwith);
if (sg != NULL)
- prefix = sg->name;
+ prefix = xstrdup(sg->name);
else if (groupwith != NULL)
- prefix = groupwith->name;
+ prefix = xstrdup(groupwith->name);
else
- prefix = group;
- } else {
- groupwith = NULL;
- sg = NULL;
- prefix = NULL;
+ prefix = session_check_name(group);
}
/* Set -d if no client. */
@@ -263,6 +255,11 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
env = environ_create();
if (c != NULL && !args_has(args, 'E'))
environ_update(global_s_options, c->environ, env);
+ add = args_first_value(args, 'e', &value);
+ while (add != NULL) {
+ environ_put(env, add, 0);
+ add = args_next_value(&value);
+ }
s = session_create(prefix, newname, cwd, env, oo, tiop);
/* Spawn the initial window. */
@@ -309,6 +306,8 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
* taking this session and needs to get MSG_READY and stay around.
*/
if (!detached) {
+ if (args_has(args, 'f'))
+ server_client_set_flags(c, args_get(args, 'f'));
if (!already_attached) {
if (~c->flags & CLIENT_CONTROL)
proc_send(c->peer, MSG_READY, -1, NULL, 0);
@@ -353,10 +352,12 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
free(cwd);
free(newname);
+ free(prefix);
return (CMD_RETURN_NORMAL);
fail:
free(cwd);
free(newname);
+ free(prefix);
return (CMD_RETURN_ERROR);
}