mirror of
https://github.com/tmux/tmux.git
synced 2024-12-13 01:48:47 +00:00
Hoist some common code out of both branches of an if/else.
This commit is contained in:
parent
a4b4b29987
commit
d1b73be6e1
@ -93,21 +93,6 @@ cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag,
|
|||||||
session_set_current(s, wl);
|
session_set_current(s, wl);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c->session != NULL) {
|
|
||||||
if (dflag) {
|
|
||||||
/*
|
|
||||||
* Can't use server_write_session in case attaching to
|
|
||||||
* the same session as currently attached to.
|
|
||||||
*/
|
|
||||||
TAILQ_FOREACH(c_loop, &clients, entry) {
|
|
||||||
if (c_loop->session != s || c == c_loop)
|
|
||||||
continue;
|
|
||||||
server_write_client(c, MSG_DETACH,
|
|
||||||
c_loop->session->name,
|
|
||||||
strlen(c_loop->session->name) + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cflag != NULL) {
|
if (cflag != NULL) {
|
||||||
ft = format_create();
|
ft = format_create();
|
||||||
format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s,
|
format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s,
|
||||||
@ -126,6 +111,21 @@ cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag,
|
|||||||
s->cwd = fd;
|
s->cwd = fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (c->session != NULL) {
|
||||||
|
if (dflag) {
|
||||||
|
/*
|
||||||
|
* Can't use server_write_session in case attaching to
|
||||||
|
* the same session as currently attached to.
|
||||||
|
*/
|
||||||
|
TAILQ_FOREACH(c_loop, &clients, entry) {
|
||||||
|
if (c_loop->session != s || c == c_loop)
|
||||||
|
continue;
|
||||||
|
server_write_client(c, MSG_DETACH,
|
||||||
|
c_loop->session->name,
|
||||||
|
strlen(c_loop->session->name) + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!Eflag) {
|
if (!Eflag) {
|
||||||
update = options_get_string(&s->options,
|
update = options_get_string(&s->options,
|
||||||
"update-environment");
|
"update-environment");
|
||||||
@ -146,24 +146,6 @@ cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag,
|
|||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cflag != NULL) {
|
|
||||||
ft = format_create();
|
|
||||||
format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s,
|
|
||||||
NULL, NULL);
|
|
||||||
cp = format_expand(ft, cflag);
|
|
||||||
format_free(ft);
|
|
||||||
|
|
||||||
fd = open(cp, O_RDONLY|O_DIRECTORY);
|
|
||||||
free(cp);
|
|
||||||
if (fd == -1) {
|
|
||||||
cmdq_error(cmdq, "bad working directory: %s",
|
|
||||||
strerror(errno));
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
close(s->cwd);
|
|
||||||
s->cwd = fd;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rflag)
|
if (rflag)
|
||||||
c->flags |= CLIENT_READONLY;
|
c->flags |= CLIENT_READONLY;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user