Hmm. As far as I can see xterm doesn't set PWD, how come xterm doesn't
have this problem?

If you make sure your shell exports PWD and add it to
update-environment, tmux will set it in the environment. Does that not
that work? It might be easier to just add PWD to update-environment by
default.


On Thu, Dec 01, 2011 at 08:58:36PM +0100, Matthias Lederhofer wrote:
> Tmux does currently not set $PWD when creating a new window.  This
> makes it impossible for the shell to figure out the path specified by
> the user, if it contains symlinks.  Example:
> 
>     $ cd /tmp
>     $ mkdir a
>     $ ln -s a b
>     $ cd b
>     $ pwd
>     /tmp/b
>     $ tmux
> 
> In tmux:
> 
>     $ pwd
>     /tmp/a
> 
> My suggestion is to make tmux aware of $PWD.  It should honor $PWD if
> it correctly points to the current directory and should set it when
> changing the directory.
> 
> If there is any need for an option to disable this behaviour I'll
> happily provide it, actually its almost implemented completely but I'm
> not sure if there is any need for an option to disable this.
> 
> diff --git a/client.c b/client.c
> index 9e5c4c6..6090844 100644
> --- a/client.c
> +++ b/client.c
> @@ -212,13 +212,20 @@ void
>  client_send_identify(int flags)
>  {
>       struct msg_identify_data        data;
> -     char                           *term;
> +     char                           *pwd, *term;
> +     struct stat                     stpwd, stdot;
>       int                             fd;
>  
>       data.flags = flags;
>  
> -     if (getcwd(data.cwd, sizeof data.cwd) == NULL)
> +     pwd = getenv("PWD");
> +     if (pwd && strlen(pwd) < sizeof data.cwd &&
> +         stat(pwd, &stpwd) == 0 && stat(".", &stdot) == 0 &&
> +         stdot.st_dev == stpwd.st_dev && stdot.st_ino == stpwd.st_ino) {
> +             strlcpy(data.cwd, pwd, sizeof data.cwd);
> +     } else if (getcwd(data.cwd, sizeof data.cwd) == NULL) {
>               *data.cwd = '\0';
> +     }
>  
>       term = getenv("TERM");
>       if (term == NULL ||
> diff --git a/cmd-respawn-pane.c b/cmd-respawn-pane.c
> index d4d67d5..a375b7f 100644
> --- a/cmd-respawn-pane.c
> +++ b/cmd-respawn-pane.c
> @@ -68,6 +68,7 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
>       environ_copy(&global_environ, &env);
>       environ_copy(&s->environ, &env);
>       server_fill_environ(s, &env);
> +     environ_set(&env, "PWD", wp->cwd);
>  
>       window_pane_reset_mode(wp);
>       screen_reinit(&wp->base);
> diff --git a/cmd-respawn-window.c b/cmd-respawn-window.c
> index eb45d17..932406a 100644
> --- a/cmd-respawn-window.c
> +++ b/cmd-respawn-window.c
> @@ -64,11 +64,6 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx 
> *ctx)
>               }
>       }
>  
> -     environ_init(&env);
> -     environ_copy(&global_environ, &env);
> -     environ_copy(&s->environ, &env);
> -     server_fill_environ(s, &env);
> -
>       wp = TAILQ_FIRST(&w->panes);
>       TAILQ_REMOVE(&w->panes, wp, entry);
>       layout_free(w);
> @@ -79,6 +74,13 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx 
> *ctx)
>               cmd = args->argv[0];
>       else
>               cmd = NULL;
> +
> +     environ_init(&env);
> +     environ_copy(&global_environ, &env);
> +     environ_copy(&s->environ, &env);
> +     server_fill_environ(s, &env);
> +     environ_set(&env, "PWD", wp->cwd);
> +
>       if (window_pane_spawn(wp, cmd, NULL, NULL, &env, s->tio, &cause) != 0) {
>               ctx->error(ctx, "respawn window failed: %s", cause);
>               xfree(cause);
> diff --git a/cmd-split-window.c b/cmd-split-window.c
> index 258c632..3e797f1 100644
> --- a/cmd-split-window.c
> +++ b/cmd-split-window.c
> @@ -68,11 +68,6 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx 
> *ctx)
>               return (-1);
>       w = wl->window;
>  
> -     environ_init(&env);
> -     environ_copy(&global_environ, &env);
> -     environ_copy(&s->environ, &env);
> -     server_fill_environ(s, &env);
> -
>       if (args->argc == 0)
>               cmd = options_get_string(&s->options, "default-command");
>       else
> @@ -85,6 +80,12 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx 
> *ctx)
>                       cwd = s->cwd;
>       }
>  
> +     environ_init(&env);
> +     environ_copy(&global_environ, &env);
> +     environ_copy(&s->environ, &env);
> +     server_fill_environ(s, &env);
> +     environ_set(&env, "PWD", cwd);
> +
>       type = LAYOUT_TOPBOTTOM;
>       if (args_has(args, 'h'))
>               type = LAYOUT_LEFTRIGHT;
> diff --git a/session.c b/session.c
> index 2fa61d2..cbd9951 100644
> --- a/session.c
> +++ b/session.c
> @@ -239,6 +239,7 @@ session_new(struct session *s,
>       environ_copy(&global_environ, &env);
>       environ_copy(&s->environ, &env);
>       server_fill_environ(s, &env);
> +     environ_set(&env, "PWD", cwd);
>  
>       shell = options_get_string(&s->options, "default-shell");
>       if (*shell == '\0' || areshell(shell))
> -- 
> 1.7.7.3
> 
> 
> ------------------------------------------------------------------------------
> All the data continuously generated in your IT infrastructure 
> contains a definitive record of customers, application performance, 
> security threats, fraudulent activity, and more. Splunk takes this 
> data and makes sense of it. IT sense. And common sense.
> http://p.sf.net/sfu/splunk-novd2d
> _______________________________________________
> tmux-users mailing list
> tmux-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/tmux-users

------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to