I've attached a patch that just does the PATH bits.
diff --git a/cmd-new-session.c b/cmd-new-session.c
index 15e411d..8953820 100644
--- a/cmd-new-session.c
+++ b/cmd-new-session.c
@@ -54,11 +54,12 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
struct window *w;
struct environ env;
struct termios tio, *tiop;
- const char *newname, *target, *update, *errstr, *template;
+ const char *newname, *target, *update, *errstr, *template, *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");
@@ -189,6 +190,13 @@ 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");
+ if (envent != NULL)
+ path = envent->value;
+ }
+
/* Construct the environment. */
environ_init(&env);
update = options_get_string(&global_s_options, "update-environment");
@@ -197,7 +205,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);
diff --git a/cmd-new-window.c b/cmd-new-window.c
index 58a5eb6..50b012a 100644
--- a/cmd-new-window.c
+++ b/cmd-new-window.c
@@ -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);
@@ -87,6 +88,13 @@ 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");
+ 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 +143,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);
diff --git a/cmd-respawn-pane.c b/cmd-respawn-pane.c
index bcde275..fbd8264 100644
--- a/cmd-respawn-pane.c
+++ b/cmd-respawn-pane.c
@@ -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,16 @@ 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");
+ 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);
diff --git a/cmd-respawn-window.c b/cmd-respawn-window.c
index e6d913c..5d5f326 100644
--- a/cmd-respawn-window.c
+++ b/cmd-respawn-window.c
@@ -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,16 @@ 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");
+ 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);
diff --git a/cmd-split-window.c b/cmd-split-window.c
index c43cb96..22a91c9 100644
--- a/cmd-split-window.c
+++ b/cmd-split-window.c
@@ -60,7 +60,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;
@@ -68,6 +68,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);
@@ -147,8 +148,16 @@ 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");
+ 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);
diff --git a/session.c b/session.c
index 0730771..19be53b 100644
--- a/session.c
+++ b/session.c
@@ -84,8 +84,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;
@@ -131,7 +132,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);
}
@@ -225,8 +226,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;
@@ -249,8 +250,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);
diff --git a/tmux.h b/tmux.h
index 5aac390..c61e221 100644
--- a/tmux.h
+++ b/tmux.h
@@ -2126,9 +2126,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);
@@ -2152,8 +2152,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);
@@ -2289,7 +2289,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 *);
@@ -2297,8 +2297,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 *);
diff --git a/window.c b/window.c
index 9a26b90..dedac72 100644
--- a/window.c
+++ b/window.c
@@ -309,8 +309,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;
@@ -320,7 +320,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];
@@ -867,6 +869,9 @@ 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);
------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users