mirror of
https://github.com/tmux/tmux.git
synced 2025-09-01 20:57:00 +00:00
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.
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user