mirror of
https://github.com/tmux/tmux.git
synced 2025-01-14 20:58:53 +00:00
Set PATH explicitly, either from client or session
environment. Previously it came from the session environment. From J Raynor.
This commit is contained in:
parent
c3b2e5eed3
commit
3e27be353d
@ -54,10 +54,12 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
struct environ env;
|
||||
struct termios tio, *tiop;
|
||||
const char *newname, *target, *update, *errstr, *template;
|
||||
const char *path;
|
||||
char *cmd, *cause, *cp;
|
||||
int detached, already_attached, idx, cwd, fd = -1;
|
||||
u_int sx, sy;
|
||||
struct format_tree *ft;
|
||||
struct environ_entry *envent;
|
||||
|
||||
if (args_has(args, 't') && (args->argc != 0 || args_has(args, 'n'))) {
|
||||
cmdq_error(cmdq, "command or window name given with target");
|
||||
@ -188,6 +190,14 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
else
|
||||
cmd = options_get_string(&global_s_options, "default-command");
|
||||
|
||||
path = NULL;
|
||||
if (c != NULL && c->session == NULL)
|
||||
envent = environ_find(&c->environ, "PATH");
|
||||
else
|
||||
envent = environ_find(&global_environ, "PATH");
|
||||
if (envent != NULL)
|
||||
path = envent->value;
|
||||
|
||||
/* Construct the environment. */
|
||||
environ_init(&env);
|
||||
update = options_get_string(&global_s_options, "update-environment");
|
||||
@ -196,7 +206,8 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
|
||||
/* Create the new session. */
|
||||
idx = -1 - options_get_number(&global_s_options, "base-index");
|
||||
s = session_create(newname, cmd, cwd, &env, tiop, idx, sx, sy, &cause);
|
||||
s = session_create(newname, cmd, path, cwd, &env, tiop, idx, sx, sy,
|
||||
&cause);
|
||||
if (s == NULL) {
|
||||
cmdq_error(cmdq, "create session failed: %s", cause);
|
||||
free(cause);
|
||||
|
@ -49,10 +49,11 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
struct session *s;
|
||||
struct winlink *wl;
|
||||
struct client *c;
|
||||
const char *cmd, *template;
|
||||
const char *cmd, *path, *template;
|
||||
char *cause, *cp;
|
||||
int idx, last, detached, cwd, fd = -1;
|
||||
struct format_tree *ft;
|
||||
struct environ_entry *envent;
|
||||
|
||||
if (args_has(args, 'a')) {
|
||||
wl = cmd_find_window(cmdq, args_get(args, 't'), &s);
|
||||
@ -77,7 +78,8 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
server_unlink_window(s, wl);
|
||||
}
|
||||
} else {
|
||||
if ((idx = cmd_find_index(cmdq, args_get(args, 't'), &s)) == -2)
|
||||
idx = cmd_find_index(cmdq, args_get(args, 't'), &s);
|
||||
if (idx == -2)
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
detached = args_has(args, 'd');
|
||||
@ -87,6 +89,14 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
else
|
||||
cmd = args->argv[0];
|
||||
|
||||
path = NULL;
|
||||
if (cmdq->client != NULL && cmdq->client->session == NULL)
|
||||
envent = environ_find(&cmdq->client->environ, "PATH");
|
||||
else
|
||||
envent = environ_find(&s->environ, "PATH");
|
||||
if (envent != NULL)
|
||||
path = envent->value;
|
||||
|
||||
if (args_has(args, 'c')) {
|
||||
ft = format_create();
|
||||
if ((c = cmd_find_client(cmdq, NULL, 1)) != NULL)
|
||||
@ -135,7 +145,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
|
||||
if (idx == -1)
|
||||
idx = -1 - options_get_number(&s->options, "base-index");
|
||||
wl = session_new(s, args_get(args, 'n'), cmd, cwd, idx, &cause);
|
||||
wl = session_new(s, args_get(args, 'n'), cmd, path, cwd, idx, &cause);
|
||||
if (wl == NULL) {
|
||||
cmdq_error(cmdq, "create window failed: %s", cause);
|
||||
free(cause);
|
||||
|
@ -48,9 +48,10 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
struct window_pane *wp;
|
||||
struct session *s;
|
||||
struct environ env;
|
||||
const char *cmd;
|
||||
const char *cmd, *path;
|
||||
char *cause;
|
||||
u_int idx;
|
||||
struct environ_entry *envent;
|
||||
|
||||
if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
@ -77,7 +78,17 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
cmd = args->argv[0];
|
||||
else
|
||||
cmd = NULL;
|
||||
if (window_pane_spawn(wp, cmd, NULL, -1, &env, s->tio, &cause) != 0) {
|
||||
|
||||
path = NULL;
|
||||
if (cmdq->client != NULL && cmdq->client->session == NULL)
|
||||
envent = environ_find(&cmdq->client->environ, "PATH");
|
||||
else
|
||||
envent = environ_find(&s->environ, "PATH");
|
||||
if (envent != NULL)
|
||||
path = envent->value;
|
||||
|
||||
if (window_pane_spawn(wp, cmd, path, NULL, -1, &env, s->tio,
|
||||
&cause) != 0) {
|
||||
cmdq_error(cmdq, "respawn pane failed: %s", cause);
|
||||
free(cause);
|
||||
environ_free(&env);
|
||||
|
@ -47,8 +47,9 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
struct window_pane *wp;
|
||||
struct session *s;
|
||||
struct environ env;
|
||||
const char *cmd;
|
||||
const char *cmd, *path;
|
||||
char *cause;
|
||||
struct environ_entry *envent;
|
||||
|
||||
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), &s)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
@ -79,7 +80,17 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
cmd = args->argv[0];
|
||||
else
|
||||
cmd = NULL;
|
||||
if (window_pane_spawn(wp, cmd, NULL, -1, &env, s->tio, &cause) != 0) {
|
||||
|
||||
path = NULL;
|
||||
if (cmdq->client != NULL && cmdq->client->session == NULL)
|
||||
envent = environ_find(&cmdq->client->environ, "PATH");
|
||||
else
|
||||
envent = environ_find(&s->environ, "PATH");
|
||||
if (envent != NULL)
|
||||
path = envent->value;
|
||||
|
||||
if (window_pane_spawn(wp, cmd, path, NULL, -1, &env, s->tio,
|
||||
&cause) != 0) {
|
||||
cmdq_error(cmdq, "respawn window failed: %s", cause);
|
||||
free(cause);
|
||||
environ_free(&env);
|
||||
|
@ -61,7 +61,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
struct window *w;
|
||||
struct window_pane *wp, *new_wp = NULL;
|
||||
struct environ env;
|
||||
const char *cmd, *shell, *template;
|
||||
const char *cmd, *path, *shell, *template;
|
||||
char *cause, *new_cause, *cp;
|
||||
u_int hlimit;
|
||||
int size, percentage, cwd, fd = -1;
|
||||
@ -69,6 +69,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
struct layout_cell *lc;
|
||||
struct client *c;
|
||||
struct format_tree *ft;
|
||||
struct environ_entry *envent;
|
||||
|
||||
if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
@ -148,8 +149,17 @@ cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
goto error;
|
||||
}
|
||||
new_wp = window_add_pane(w, hlimit);
|
||||
|
||||
path = NULL;
|
||||
if (cmdq->client != NULL && cmdq->client->session == NULL)
|
||||
envent = environ_find(&cmdq->client->environ, "PATH");
|
||||
else
|
||||
envent = environ_find(&s->environ, "PATH");
|
||||
if (envent != NULL)
|
||||
path = envent->value;
|
||||
|
||||
if (window_pane_spawn(
|
||||
new_wp, cmd, shell, cwd, &env, s->tio, &cause) != 0)
|
||||
new_wp, cmd, path, shell, cwd, &env, s->tio, &cause) != 0)
|
||||
goto error;
|
||||
layout_assign_pane(lc, new_wp);
|
||||
|
||||
|
15
session.c
15
session.c
@ -85,8 +85,9 @@ session_find_by_id(u_int id)
|
||||
|
||||
/* Create a new session. */
|
||||
struct session *
|
||||
session_create(const char *name, const char *cmd, int cwd, struct environ *env,
|
||||
struct termios *tio, int idx, u_int sx, u_int sy, char **cause)
|
||||
session_create(const char *name, const char *cmd, const char *path, int cwd,
|
||||
struct environ *env, struct termios *tio, int idx, u_int sx, u_int sy,
|
||||
char **cause)
|
||||
{
|
||||
struct session *s;
|
||||
|
||||
@ -132,7 +133,7 @@ session_create(const char *name, const char *cmd, int cwd, struct environ *env,
|
||||
RB_INSERT(sessions, &sessions, s);
|
||||
|
||||
if (cmd != NULL) {
|
||||
if (session_new(s, NULL, cmd, cwd, idx, cause) == NULL) {
|
||||
if (session_new(s, NULL, cmd, path, cwd, idx, cause) == NULL) {
|
||||
session_destroy(s);
|
||||
return (NULL);
|
||||
}
|
||||
@ -226,8 +227,8 @@ session_previous_session(struct session *s)
|
||||
|
||||
/* Create a new window on a session. */
|
||||
struct winlink *
|
||||
session_new(struct session *s, const char *name, const char *cmd, int cwd,
|
||||
int idx, char **cause)
|
||||
session_new(struct session *s, const char *name, const char *cmd,
|
||||
const char *path, int cwd, int idx, char **cause)
|
||||
{
|
||||
struct window *w;
|
||||
struct winlink *wl;
|
||||
@ -250,8 +251,8 @@ session_new(struct session *s, const char *name, const char *cmd, int cwd,
|
||||
shell = _PATH_BSHELL;
|
||||
|
||||
hlimit = options_get_number(&s->options, "history-limit");
|
||||
w = window_create(name, cmd, shell, cwd, &env, s->tio, s->sx, s->sy,
|
||||
hlimit, cause);
|
||||
w = window_create(name, cmd, path, shell, cwd, &env, s->tio, s->sx,
|
||||
s->sy, hlimit, cause);
|
||||
if (w == NULL) {
|
||||
winlink_remove(&s->windows, wl);
|
||||
environ_free(&env);
|
||||
|
16
tmux.h
16
tmux.h
@ -2129,9 +2129,9 @@ void winlink_stack_remove(struct winlink_stack *, struct winlink *);
|
||||
int window_index(struct window *, u_int *);
|
||||
struct window *window_find_by_id(u_int);
|
||||
struct window *window_create1(u_int, u_int);
|
||||
struct window *window_create(const char *, const char *, const char *, int,
|
||||
struct environ *, struct termios *, u_int, u_int, u_int,
|
||||
char **);
|
||||
struct window *window_create(const char *, const char *, const char *,
|
||||
const char *, int, struct environ *, struct termios *,
|
||||
u_int, u_int, u_int, char **);
|
||||
void window_destroy(struct window *);
|
||||
struct window_pane *window_get_active_at(struct window *, u_int, u_int);
|
||||
void window_set_active_at(struct window *, u_int, u_int);
|
||||
@ -2156,8 +2156,8 @@ struct window_pane *window_pane_create(struct window *, u_int, u_int, u_int);
|
||||
void window_pane_destroy(struct window_pane *);
|
||||
void window_pane_timer_start(struct window_pane *);
|
||||
int window_pane_spawn(struct window_pane *, const char *,
|
||||
const char *, int, struct environ *, struct termios *,
|
||||
char **);
|
||||
const char *, const char *, int, struct environ *,
|
||||
struct termios *, char **);
|
||||
void window_pane_resize(struct window_pane *, u_int, u_int);
|
||||
void window_pane_alternate_on(struct window_pane *,
|
||||
struct grid_cell *, int);
|
||||
@ -2293,7 +2293,7 @@ RB_PROTOTYPE(sessions, session, entry, session_cmp);
|
||||
int session_alive(struct session *);
|
||||
struct session *session_find(const char *);
|
||||
struct session *session_find_by_id(u_int);
|
||||
struct session *session_create(const char *, const char *, int,
|
||||
struct session *session_create(const char *, const char *, const char *, int,
|
||||
struct environ *, struct termios *, int, u_int, u_int,
|
||||
char **);
|
||||
void session_destroy(struct session *);
|
||||
@ -2301,8 +2301,8 @@ int session_check_name(const char *);
|
||||
void session_update_activity(struct session *);
|
||||
struct session *session_next_session(struct session *);
|
||||
struct session *session_previous_session(struct session *);
|
||||
struct winlink *session_new(struct session *, const char *, const char *, int,
|
||||
int, char **);
|
||||
struct winlink *session_new(struct session *, const char *, const char *,
|
||||
const char *, int, int, char **);
|
||||
struct winlink *session_attach(
|
||||
struct session *, struct window *, int, char **);
|
||||
int session_detach(struct session *, struct winlink *);
|
||||
|
14
window.c
14
window.c
@ -308,8 +308,8 @@ window_create1(u_int sx, u_int sy)
|
||||
}
|
||||
|
||||
struct window *
|
||||
window_create(const char *name, const char *cmd, const char *shell,
|
||||
int cwd, struct environ *env, struct termios *tio,
|
||||
window_create(const char *name, const char *cmd, const char *path,
|
||||
const char *shell, int cwd, struct environ *env, struct termios *tio,
|
||||
u_int sx, u_int sy, u_int hlimit, char **cause)
|
||||
{
|
||||
struct window *w;
|
||||
@ -319,7 +319,8 @@ window_create(const char *name, const char *cmd, const char *shell,
|
||||
wp = window_add_pane(w, hlimit);
|
||||
layout_init(w, wp);
|
||||
|
||||
if (window_pane_spawn(wp, cmd, shell, cwd, env, tio, cause) != 0) {
|
||||
if (window_pane_spawn(wp, cmd, path, shell, cwd, env, tio,
|
||||
cause) != 0) {
|
||||
window_destroy(w);
|
||||
return (NULL);
|
||||
}
|
||||
@ -810,8 +811,9 @@ window_pane_destroy(struct window_pane *wp)
|
||||
}
|
||||
|
||||
int
|
||||
window_pane_spawn(struct window_pane *wp, const char *cmd, const char *shell,
|
||||
int cwd, struct environ *env, struct termios *tio, char **cause)
|
||||
window_pane_spawn(struct window_pane *wp, const char *cmd, const char *path,
|
||||
const char *shell, int cwd, struct environ *env, struct termios *tio,
|
||||
char **cause)
|
||||
{
|
||||
struct winsize ws;
|
||||
char *argv0, paneid[16];
|
||||
@ -860,6 +862,8 @@ window_pane_spawn(struct window_pane *wp, const char *cmd, const char *shell,
|
||||
|
||||
closefrom(STDERR_FILENO + 1);
|
||||
|
||||
if (path != NULL)
|
||||
environ_set(env, "PATH", path);
|
||||
xsnprintf(paneid, sizeof paneid, "%%%u", wp->id);
|
||||
environ_set(env, "TMUX_PANE", paneid);
|
||||
environ_push(env);
|
||||
|
Loading…
Reference in New Issue
Block a user