diff options
author | nicm <nicm> | 2019-11-14 08:00:30 +0000 |
---|---|---|
committer | nicm <nicm> | 2019-11-14 08:00:30 +0000 |
commit | 2dbf062a891e992b438a0923b9ffd79638014872 (patch) | |
tree | 6ff586dad0ebed6bf449b68a3ef0072c96190159 /cmd-new-session.c | |
parent | eb399e64d5c8f1b18e912fdf1c5488d602f78d80 (diff) | |
download | rtmux-2dbf062a891e992b438a0923b9ffd79638014872.tar.gz rtmux-2dbf062a891e992b438a0923b9ffd79638014872.tar.bz2 rtmux-2dbf062a891e992b438a0923b9ffd79638014872.zip |
Change new-session -A without a session name (that is, no -s option
also) to attach to the best existing session like attach-session rather
than creating a new one.
Diffstat (limited to 'cmd-new-session.c')
-rw-r--r-- | cmd-new-session.c | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/cmd-new-session.c b/cmd-new-session.c index c7c407c6..c76b564e 100644 --- a/cmd-new-session.c +++ b/cmd-new-session.c @@ -94,26 +94,31 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item) return (CMD_RETURN_ERROR); } - if (args_has(args, 's')) { - newname = format_single(item, args_get(args, 's'), c, NULL, - NULL, NULL); + 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; } - if ((as = session_find(newname)) != NULL) { - if (args_has(args, 'A')) { - retval = cmd_attach_session(item, - newname, args_has(args, 'D'), - args_has(args, 'X'), 0, NULL, - args_has(args, 'E')); - free(newname); - return (retval); - } - cmdq_error(item, "duplicate session: %s", newname); - goto fail; + } + if (args_has(args, 'A')) { + if (newname != NULL) + as = session_find(newname); + else + as = item->target.s; + if (as != NULL) { + retval = cmd_attach_session(item, as->name, + args_has(args, 'D'), args_has(args, 'X'), 0, NULL, + args_has(args, 'E')); + free(newname); + return (retval); } } + if (newname != NULL && session_find(newname) != NULL) { + cmdq_error(item, "duplicate session: %s", newname); + goto fail; + } /* Is this going to be part of a session group? */ group = args_get(args, 't'); |