diff options
author | nicm <nicm> | 2017-02-09 15:04:53 +0000 |
---|---|---|
committer | nicm <nicm> | 2017-02-09 15:04:53 +0000 |
commit | c6a3446398648fc2cc3682c351b57b9bfe5bc5f0 (patch) | |
tree | 7bd0ac8c644eb3037e1fd9633e6a1ad517fa3d01 /cmd-new-session.c | |
parent | 8de4c15dfa9d15d259d295b6f2e121c980082c79 (diff) | |
download | rtmux-c6a3446398648fc2cc3682c351b57b9bfe5bc5f0.tar.gz rtmux-c6a3446398648fc2cc3682c351b57b9bfe5bc5f0.tar.bz2 rtmux-c6a3446398648fc2cc3682c351b57b9bfe5bc5f0.zip |
Instead of numbering session groups, give them a name which may be given
to -t instead of a target session. Also allow them to contain only one
session.
Diffstat (limited to 'cmd-new-session.c')
-rw-r--r-- | cmd-new-session.c | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/cmd-new-session.c b/cmd-new-session.c index deda88f2..08fc6065 100644 --- a/cmd-new-session.c +++ b/cmd-new-session.c @@ -68,12 +68,12 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; struct client *c = item->client; - struct session *s, *as; - struct session *groupwith = item->state.tflag.s; + struct session *s, *as, *groupwith; struct window *w; struct environ *env; struct termios tio, *tiop; - const char *newname, *target, *errstr, *template; + struct session_group *sg; + const char *newname, *errstr, *template, *group, *prefix; const char *path, *cmd, *cwd, *to_free = NULL; char **argv, *cause, *cp; int detached, already_attached, idx, argc; @@ -119,13 +119,29 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item) } } - if ((target = args_get(args, 't')) != NULL) { + /* Is this going to be part of a session group? */ + group = args_get(args, 't'); + if (group != NULL) { + groupwith = item->state.tflag.s; if (groupwith == NULL) { - cmdq_error(item, "no such session: %s", target); - goto error; - } - } else + if (!session_check_name(group)) { + cmdq_error(item, "bad group name: %s", group); + goto error; + } + sg = session_group_find(group); + } else + sg = session_group_contains(groupwith); + if (sg != NULL) + prefix = sg->name; + else if (groupwith != NULL) + prefix = groupwith->name; + else + prefix = group; + } else { groupwith = NULL; + sg = NULL; + prefix = NULL; + } /* Set -d if no client. */ detached = args_has(args, 'd'); @@ -213,7 +229,7 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item) if (!args_has(args, 't') && args->argc != 0) { argc = args->argc; argv = args->argv; - } else if (groupwith == NULL) { + } else if (sg == NULL && groupwith == NULL) { cmd = options_get_string(global_s_options, "default-command"); if (cmd != NULL && *cmd != '\0') { argc = 1; @@ -239,8 +255,8 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item) /* Create the new session. */ idx = -1 - options_get_number(global_s_options, "base-index"); - s = session_create(newname, argc, argv, path, cwd, env, tiop, idx, sx, - sy, &cause); + s = session_create(prefix, newname, argc, argv, path, cwd, env, tiop, + idx, sx, sy, &cause); environ_free(env); if (s == NULL) { cmdq_error(item, "create session failed: %s", cause); @@ -259,8 +275,15 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item) * If a target session is given, this is to be part of a session group, * so add it to the group and synchronize. */ - if (groupwith != NULL) { - session_group_add(groupwith, s); + if (group != NULL) { + if (sg == NULL) { + if (groupwith != NULL) { + sg = session_group_new(groupwith->name); + session_group_add(sg, groupwith); + } else + sg = session_group_new(group); + } + session_group_add(sg, s); session_group_synchronize_to(s); session_select(s, RB_MIN(winlinks, &s->windows)->idx); } |