mirror of
https://github.com/tmux/tmux.git
synced 2025-01-05 23:38:48 +00:00
Change so that an empty session name always means the current sessions
even if given with, for example, -t '', and explicitly forbid empty session names and those containing a : when they are created.
This commit is contained in:
parent
c8a14def9f
commit
ec89eb9552
@ -68,9 +68,15 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
u_int sx, sy, i;
|
u_int sx, sy, i;
|
||||||
|
|
||||||
newname = args_get(args, 's');
|
newname = args_get(args, 's');
|
||||||
if (newname != NULL && session_find(newname) != NULL) {
|
if (newname != NULL) {
|
||||||
ctx->error(ctx, "duplicate session: %s", newname);
|
if (!session_check_name(newname)) {
|
||||||
return (-1);
|
ctx->error(ctx, "bad session name: %s", newname);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if (session_find(newname) != NULL) {
|
||||||
|
ctx->error(ctx, "duplicate session: %s", newname);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
target = args_get(args, 't');
|
target = args_get(args, 't');
|
||||||
|
@ -46,6 +46,10 @@ cmd_rename_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
const char *newname;
|
const char *newname;
|
||||||
|
|
||||||
newname = args->argv[0];
|
newname = args->argv[0];
|
||||||
|
if (!session_check_name(newname)) {
|
||||||
|
ctx->error(ctx, "bad session name: %s", newname);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
if (session_find(newname) != NULL) {
|
if (session_find(newname) != NULL) {
|
||||||
ctx->error(ctx, "duplicate session: %s", newname);
|
ctx->error(ctx, "duplicate session: %s", newname);
|
||||||
return (-1);
|
return (-1);
|
||||||
|
10
cmd.c
10
cmd.c
@ -725,6 +725,12 @@ cmd_find_session(struct cmd_ctx *ctx, const char *arg, int prefer_unattached)
|
|||||||
if (arglen != 0 && tmparg[arglen - 1] == ':')
|
if (arglen != 0 && tmparg[arglen - 1] == ':')
|
||||||
tmparg[arglen - 1] = '\0';
|
tmparg[arglen - 1] = '\0';
|
||||||
|
|
||||||
|
/* An empty session name is the current session. */
|
||||||
|
if (*tmparg == '\0') {
|
||||||
|
xfree (tmparg);
|
||||||
|
return (cmd_current_session(ctx, prefer_unattached));
|
||||||
|
}
|
||||||
|
|
||||||
/* Find the session, if any. */
|
/* Find the session, if any. */
|
||||||
s = cmd_lookup_session(tmparg, &ambiguous);
|
s = cmd_lookup_session(tmparg, &ambiguous);
|
||||||
|
|
||||||
@ -840,7 +846,7 @@ no_colon:
|
|||||||
lookup_session:
|
lookup_session:
|
||||||
if (ambiguous)
|
if (ambiguous)
|
||||||
goto not_found;
|
goto not_found;
|
||||||
if ((s = cmd_lookup_session(arg, &ambiguous)) == NULL)
|
if (*arg != '\0' && (s = cmd_lookup_session(arg, &ambiguous)) == NULL)
|
||||||
goto no_session;
|
goto no_session;
|
||||||
|
|
||||||
if (sp != NULL)
|
if (sp != NULL)
|
||||||
@ -981,7 +987,7 @@ no_colon:
|
|||||||
lookup_session:
|
lookup_session:
|
||||||
if (ambiguous)
|
if (ambiguous)
|
||||||
goto not_found;
|
goto not_found;
|
||||||
if ((s = cmd_lookup_session(arg, &ambiguous)) == NULL)
|
if (*arg != '\0' && (s = cmd_lookup_session(arg, &ambiguous)) == NULL)
|
||||||
goto no_session;
|
goto no_session;
|
||||||
|
|
||||||
if (sp != NULL)
|
if (sp != NULL)
|
||||||
|
@ -164,6 +164,13 @@ session_destroy(struct session *s)
|
|||||||
RB_INSERT(sessions, &dead_sessions, s);
|
RB_INSERT(sessions, &dead_sessions, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check a session name is valid: not empty and no colons. */
|
||||||
|
int
|
||||||
|
session_check_name(const char *name)
|
||||||
|
{
|
||||||
|
return (*name != '\0' && strchr(name, ':') == NULL);
|
||||||
|
}
|
||||||
|
|
||||||
/* Update session active time. */
|
/* Update session active time. */
|
||||||
void
|
void
|
||||||
session_update_activity(struct session *s)
|
session_update_activity(struct session *s)
|
||||||
|
1
tmux.h
1
tmux.h
@ -1978,6 +1978,7 @@ struct session *session_create(const char *, const char *, const char *,
|
|||||||
struct environ *, struct termios *, int, u_int, u_int,
|
struct environ *, struct termios *, int, u_int, u_int,
|
||||||
char **);
|
char **);
|
||||||
void session_destroy(struct session *);
|
void session_destroy(struct session *);
|
||||||
|
int session_check_name(const char *);
|
||||||
void session_update_activity(struct session *);
|
void session_update_activity(struct session *);
|
||||||
struct session *session_next_session(struct session *);
|
struct session *session_next_session(struct session *);
|
||||||
struct session *session_previous_session(struct session *);
|
struct session *session_previous_session(struct session *);
|
||||||
|
Loading…
Reference in New Issue
Block a user