mirror of
https://github.com/tmux/tmux.git
synced 2024-11-10 13:48:48 +00:00
Add -E flag when attaching or switching client to bypass
update-environment, from Steven Lu.
This commit is contained in:
parent
ed6c036ee3
commit
c4e811e519
@ -34,18 +34,18 @@ enum cmd_retval cmd_attach_session_exec(struct cmd *, struct cmd_q *);
|
|||||||
|
|
||||||
const struct cmd_entry cmd_attach_session_entry = {
|
const struct cmd_entry cmd_attach_session_entry = {
|
||||||
"attach-session", "attach",
|
"attach-session", "attach",
|
||||||
"c:drt:", 0, 0,
|
"c:dErt:", 0, 0,
|
||||||
"[-dr] [-c working-directory] " CMD_TARGET_SESSION_USAGE,
|
"[-dEr] [-c working-directory] " CMD_TARGET_SESSION_USAGE,
|
||||||
CMD_STARTSERVER,
|
CMD_STARTSERVER,
|
||||||
cmd_attach_session_exec
|
cmd_attach_session_exec
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cmd_retval
|
enum cmd_retval
|
||||||
cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag,
|
cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag,
|
||||||
const char *cflag)
|
const char *cflag, int Eflag)
|
||||||
{
|
{
|
||||||
struct session *s;
|
struct session *s;
|
||||||
struct client *c;
|
struct client *c = cmdq->client, *c_loop;
|
||||||
struct winlink *wl = NULL;
|
struct winlink *wl = NULL;
|
||||||
struct window *w = NULL;
|
struct window *w = NULL;
|
||||||
struct window_pane *wp = NULL;
|
struct window_pane *wp = NULL;
|
||||||
@ -79,9 +79,9 @@ cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag,
|
|||||||
wl = winlink_find_by_window(&s->windows, w);
|
wl = winlink_find_by_window(&s->windows, w);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmdq->client == NULL)
|
if (c == NULL)
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
if (server_client_check_nested(cmdq->client)) {
|
if (server_client_check_nested(c)) {
|
||||||
cmdq_error(cmdq, "sessions should be nested with care, "
|
cmdq_error(cmdq, "sessions should be nested with care, "
|
||||||
"unset $TMUX to force");
|
"unset $TMUX to force");
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
@ -93,18 +93,18 @@ 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 (cmdq->client->session != NULL) {
|
if (c->session != NULL) {
|
||||||
if (dflag) {
|
if (dflag) {
|
||||||
/*
|
/*
|
||||||
* Can't use server_write_session in case attaching to
|
* Can't use server_write_session in case attaching to
|
||||||
* the same session as currently attached to.
|
* the same session as currently attached to.
|
||||||
*/
|
*/
|
||||||
TAILQ_FOREACH(c, &clients, entry) {
|
TAILQ_FOREACH(c_loop, &clients, entry) {
|
||||||
if (c->session != s || c == cmdq->client)
|
if (c_loop->session != s || c == c)
|
||||||
continue;
|
continue;
|
||||||
server_write_client(c, MSG_DETACH,
|
server_write_client(c, MSG_DETACH,
|
||||||
c->session->name,
|
c_loop->session->name,
|
||||||
strlen(c->session->name) + 1);
|
strlen(c_loop->session->name) + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,13 +126,13 @@ cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag,
|
|||||||
s->cwd = fd;
|
s->cwd = fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdq->client->session = s;
|
c->session = s;
|
||||||
notify_attached_session_changed(cmdq->client);
|
notify_attached_session_changed(c);
|
||||||
session_update_activity(s);
|
session_update_activity(s);
|
||||||
server_redraw_client(cmdq->client);
|
server_redraw_client(c);
|
||||||
s->curw->flags &= ~WINLINK_ALERTFLAGS;
|
s->curw->flags &= ~WINLINK_ALERTFLAGS;
|
||||||
} else {
|
} else {
|
||||||
if (server_client_open(cmdq->client, &cause) != 0) {
|
if (server_client_open(c, &cause) != 0) {
|
||||||
cmdq_error(cmdq, "open terminal failed: %s", cause);
|
cmdq_error(cmdq, "open terminal failed: %s", cause);
|
||||||
free(cause);
|
free(cause);
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
@ -157,23 +157,26 @@ cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (rflag)
|
if (rflag)
|
||||||
cmdq->client->flags |= CLIENT_READONLY;
|
c->flags |= CLIENT_READONLY;
|
||||||
|
|
||||||
if (dflag) {
|
if (dflag) {
|
||||||
server_write_session(s, MSG_DETACH, s->name,
|
server_write_session(s, MSG_DETACH, s->name,
|
||||||
strlen(s->name) + 1);
|
strlen(s->name) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
update = options_get_string(&s->options, "update-environment");
|
if (!Eflag) {
|
||||||
environ_update(update, &cmdq->client->environ, &s->environ);
|
update = options_get_string(&s->options,
|
||||||
|
"update-environment");
|
||||||
|
environ_update(update, &c->environ, &s->environ);
|
||||||
|
}
|
||||||
|
|
||||||
cmdq->client->session = s;
|
c->session = s;
|
||||||
notify_attached_session_changed(cmdq->client);
|
notify_attached_session_changed(c);
|
||||||
session_update_activity(s);
|
session_update_activity(s);
|
||||||
server_redraw_client(cmdq->client);
|
server_redraw_client(c);
|
||||||
s->curw->flags &= ~WINLINK_ALERTFLAGS;
|
s->curw->flags &= ~WINLINK_ALERTFLAGS;
|
||||||
|
|
||||||
server_write_ready(cmdq->client);
|
server_write_ready(c);
|
||||||
cmdq->client_exit = 0;
|
cmdq->client_exit = 0;
|
||||||
}
|
}
|
||||||
recalculate_sizes();
|
recalculate_sizes();
|
||||||
@ -188,5 +191,6 @@ cmd_attach_session_exec(struct cmd *self, struct cmd_q *cmdq)
|
|||||||
struct args *args = self->args;
|
struct args *args = self->args;
|
||||||
|
|
||||||
return (cmd_attach_session(cmdq, args_get(args, 't'),
|
return (cmd_attach_session(cmdq, args_get(args, 't'),
|
||||||
args_has(args, 'd'), args_has(args, 'r'), args_get(args, 'c')));
|
args_has(args, 'd'), args_has(args, 'r'), args_get(args, 'c'),
|
||||||
|
args_has(args, 'E')));
|
||||||
}
|
}
|
||||||
|
@ -37,8 +37,8 @@ enum cmd_retval cmd_new_session_exec(struct cmd *, struct cmd_q *);
|
|||||||
|
|
||||||
const struct cmd_entry cmd_new_session_entry = {
|
const struct cmd_entry cmd_new_session_entry = {
|
||||||
"new-session", "new",
|
"new-session", "new",
|
||||||
"Ac:dDF:n:Ps:t:x:y:", 0, -1,
|
"Ac:dDEF:n:Ps:t:x:y:", 0, -1,
|
||||||
"[-AdDP] [-c start-directory] [-F format] [-n window-name] "
|
"[-AdDEP] [-c start-directory] [-F format] [-n window-name] "
|
||||||
"[-s session-name] " CMD_TARGET_SESSION_USAGE " [-x width] "
|
"[-s session-name] " CMD_TARGET_SESSION_USAGE " [-x width] "
|
||||||
"[-y height] [command]",
|
"[-y height] [command]",
|
||||||
CMD_STARTSERVER,
|
CMD_STARTSERVER,
|
||||||
@ -91,7 +91,8 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
|
|||||||
if (session_find(newname) != NULL) {
|
if (session_find(newname) != NULL) {
|
||||||
if (args_has(args, 'A')) {
|
if (args_has(args, 'A')) {
|
||||||
return (cmd_attach_session(cmdq, newname,
|
return (cmd_attach_session(cmdq, newname,
|
||||||
args_has(args, 'D'), 0, NULL));
|
args_has(args, 'D'), 0, NULL,
|
||||||
|
args_has(args, 'E')));
|
||||||
}
|
}
|
||||||
cmdq_error(cmdq, "duplicate session: %s", newname);
|
cmdq_error(cmdq, "duplicate session: %s", newname);
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
@ -230,9 +231,11 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
|
|||||||
|
|
||||||
/* Construct the environment. */
|
/* Construct the environment. */
|
||||||
environ_init(&env);
|
environ_init(&env);
|
||||||
update = options_get_string(&global_s_options, "update-environment");
|
if (c != NULL && !args_has(args, 'E')) {
|
||||||
if (c != NULL)
|
update = options_get_string(&global_s_options,
|
||||||
|
"update-environment");
|
||||||
environ_update(update, &c->environ, &env);
|
environ_update(update, &c->environ, &env);
|
||||||
|
}
|
||||||
|
|
||||||
/* Create the new session. */
|
/* Create the new session. */
|
||||||
idx = -1 - options_get_number(&global_s_options, "base-index");
|
idx = -1 - options_get_number(&global_s_options, "base-index");
|
||||||
|
@ -31,8 +31,8 @@ enum cmd_retval cmd_switch_client_exec(struct cmd *, struct cmd_q *);
|
|||||||
|
|
||||||
const struct cmd_entry cmd_switch_client_entry = {
|
const struct cmd_entry cmd_switch_client_entry = {
|
||||||
"switch-client", "switchc",
|
"switch-client", "switchc",
|
||||||
"lc:npt:rT:", 0, 0,
|
"lc:Enpt:rT:", 0, 0,
|
||||||
"[-lnpr] [-c target-client] [-t target-session] [-T key-table]",
|
"[-Elnpr] [-c target-client] [-t target-session] [-T key-table]",
|
||||||
CMD_READONLY,
|
CMD_READONLY,
|
||||||
cmd_switch_client_exec
|
cmd_switch_client_exec
|
||||||
};
|
};
|
||||||
@ -119,7 +119,7 @@ cmd_switch_client_exec(struct cmd *self, struct cmd_q *cmdq)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c != NULL && s != c->session) {
|
if (c != NULL && s != c->session && !args_has(args, 'E')) {
|
||||||
update = options_get_string(&s->options, "update-environment");
|
update = options_get_string(&s->options, "update-environment");
|
||||||
environ_update(update, &c->environ, &s->environ);
|
environ_update(update, &c->environ, &s->environ);
|
||||||
}
|
}
|
||||||
|
25
tmux.1
25
tmux.1
@ -670,7 +670,7 @@ section.
|
|||||||
The following commands are available to manage clients and sessions:
|
The following commands are available to manage clients and sessions:
|
||||||
.Bl -tag -width Ds
|
.Bl -tag -width Ds
|
||||||
.It Xo Ic attach-session
|
.It Xo Ic attach-session
|
||||||
.Op Fl dr
|
.Op Fl dEr
|
||||||
.Op Fl c Ar working-directory
|
.Op Fl c Ar working-directory
|
||||||
.Op Fl t Ar target-session
|
.Op Fl t Ar target-session
|
||||||
.Xc
|
.Xc
|
||||||
@ -709,6 +709,12 @@ session.
|
|||||||
.Fl c
|
.Fl c
|
||||||
will set the session working directory (used for new windows) to
|
will set the session working directory (used for new windows) to
|
||||||
.Ar working-directory .
|
.Ar working-directory .
|
||||||
|
.Pp
|
||||||
|
If
|
||||||
|
.Fl E
|
||||||
|
is used,
|
||||||
|
.Ic update-environment
|
||||||
|
option will not be applied.
|
||||||
.It Xo Ic detach-client
|
.It Xo Ic detach-client
|
||||||
.Op Fl P
|
.Op Fl P
|
||||||
.Op Fl a
|
.Op Fl a
|
||||||
@ -783,7 +789,7 @@ command.
|
|||||||
Lock all clients attached to
|
Lock all clients attached to
|
||||||
.Ar target-session .
|
.Ar target-session .
|
||||||
.It Xo Ic new-session
|
.It Xo Ic new-session
|
||||||
.Op Fl AdDP
|
.Op Fl AdDEP
|
||||||
.Op Fl c Ar start-directory
|
.Op Fl c Ar start-directory
|
||||||
.Op Fl F Ar format
|
.Op Fl F Ar format
|
||||||
.Op Fl n Ar window-name
|
.Op Fl n Ar window-name
|
||||||
@ -858,6 +864,13 @@ By default, it uses the format
|
|||||||
.Ql #{session_name}:
|
.Ql #{session_name}:
|
||||||
but a different format may be specified with
|
but a different format may be specified with
|
||||||
.Fl F .
|
.Fl F .
|
||||||
|
.Pp
|
||||||
|
If
|
||||||
|
.Fl E
|
||||||
|
is used,
|
||||||
|
.Ic update-environment
|
||||||
|
option will not be applied.
|
||||||
|
.Ic update-environment .
|
||||||
.It Xo Ic refresh-client
|
.It Xo Ic refresh-client
|
||||||
.Op Fl S
|
.Op Fl S
|
||||||
.Op Fl t Ar target-client
|
.Op Fl t Ar target-client
|
||||||
@ -912,7 +925,7 @@ Suspend a client by sending
|
|||||||
.Dv SIGTSTP
|
.Dv SIGTSTP
|
||||||
(tty stop).
|
(tty stop).
|
||||||
.It Xo Ic switch-client
|
.It Xo Ic switch-client
|
||||||
.Op Fl lnpr
|
.Op Fl Elnpr
|
||||||
.Op Fl c Ar target-client
|
.Op Fl c Ar target-client
|
||||||
.Op Fl t Ar target-session
|
.Op Fl t Ar target-session
|
||||||
.Op Fl T Ar key-table
|
.Op Fl T Ar key-table
|
||||||
@ -934,6 +947,12 @@ toggles whether a client is read-only (see the
|
|||||||
.Ic attach-session
|
.Ic attach-session
|
||||||
command).
|
command).
|
||||||
.Pp
|
.Pp
|
||||||
|
If
|
||||||
|
.Fl E
|
||||||
|
is used,
|
||||||
|
.Ic update-environment
|
||||||
|
option will not be applied.
|
||||||
|
.Pp
|
||||||
.Fl T
|
.Fl T
|
||||||
sets the client's key table; the next key from the client will be interpreted from
|
sets the client's key table; the next key from the client will be interpreted from
|
||||||
.Ar key-table .
|
.Ar key-table .
|
||||||
|
2
tmux.h
2
tmux.h
@ -1801,7 +1801,7 @@ extern const struct cmd_entry cmd_wait_for_entry;
|
|||||||
|
|
||||||
/* cmd-attach-session.c */
|
/* cmd-attach-session.c */
|
||||||
enum cmd_retval cmd_attach_session(struct cmd_q *, const char *, int, int,
|
enum cmd_retval cmd_attach_session(struct cmd_q *, const char *, int, int,
|
||||||
const char *);
|
const char *, int);
|
||||||
|
|
||||||
/* cmd-list.c */
|
/* cmd-list.c */
|
||||||
struct cmd_list *cmd_list_parse(int, char **, const char *, u_int, char **);
|
struct cmd_list *cmd_list_parse(int, char **, const char *, u_int, char **);
|
||||||
|
Loading…
Reference in New Issue
Block a user