On Sat, Dec 03, 2011 at 06:05:44PM +0100, Matthias Lederhofer wrote:
> Nicholas Marriott <nicholas.marri...@gmail.com> wrote:
> > 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.
> 
> The terminal emulator does not set $PWD afaik but only pass it on, it
> should have nothing to do with the terminal tmux is run from.
> 
> My previous example works only if there is a server running already
> and it was not started from the symlinked directory (i.e. server's PWD
> is different from /tmp/b).

I'm not really convinced by all the PWD talk, the canonical way to find
the current working directory is to call getcwd(). Not to use PWD, that
is just a shell convenience. I don't think applications should ever need
to check PWD rather than calling getcwd(). They might not even be run
from a shell.

AFAICT getcwd() does not collapse symlinks, so I'm not sure what your
issue is... I can't actually reproduce your original problem. If I do:

$ cd /tmp
$ mkdir a
$ ln -s a b
$ cd b
$ pwd
/tmp/b
$ pwd -P
/tmp/a
$ pkill tmux
$ tmux new
<inside tmux>
$ pwd
/tmp/b
$ pwd -P
/tmp/a

Am I doing something incorrect here?

I did at one point consider just storing PWD in the tmux environment and
dropping the various cwd members. Then whether or not it is updated
would be entirely controlled by update-environment. This might be the
best solution but still I think we should use getcwd() for the original
working directory, not PWD. That is:

- In the client, force PWD to getcwd() in the environment sent to the
  server.

- Add a comment marking the cwd part of the identify struct as unused
  and remove cwd from the session. It may need to stick around in the
  pane and window for respawning, in case the user has changed the
  environment. In fact, perhaps we should save the WHOLE environment for
  respawning.

- Add PWD to update-environment by default.

- Call chdir() to the value of PWD after fork or forkpty.

Then the question of whether we update the working directory for new
sessions or on attach or whatever is moot - it is handled by
update-environment the same as everything else.

> 
> Adding PWD to update-environ works for spawning new sessions but it will
> break when attaching to an existing session from another path.  New
> windows in this session get the wrong $PWD.
> 
> Additionally when setting the default-path the user has to set $PWD
> manually too.  And even then windows using remain-on-exit will get the
> wrong $PWD when respawning.  All this should be fixed with this patch.

Respawning windows is supposed to recreate them in the same state as
before (I know it doesn't really right now) so they shouldn't
necessarily reflect any working directory changes.

> 
> Through all this I realised that tmux new will copy the whole
> environment when no server is running yet.  If a server is running
> already only the update-environ variables are copied.  I find this a bit
> inconsistent that it makes a difference if a server is already running
> or not.  Wouldn't it make more sense to copy the whole environment for
> every new session?  For example CFLAGS="-Wall -W" tmux does set the

Well, perhaps. But then you can't override parts of the environment.

One idea when the environment stuff was added was to reverse the sense
so the global environment overrides the session environment rather than
vice versa, but that is inconsistent with options...

This is an edge case but my feeling is that it is more intuitive for
tmux to not change the session environment around under you except for
some obvious, easily configurable cases like DISPLAY.

Replacing the whole thing on attach has it's own problems. For example,
what if you have two or three clients on the same session? When the
session is created is the only time we are guaranteed there is only one
source environment. Or what if I don't want it changed?

A nice - and probably relatively easy - change here would be to make
update-environment accept fnmatch() wildcards, so those who want the
entire environment updated could just add "*" and those who wanted the
entire environment removed add "-*".

> CFLAGS variable for the windows in the new session if no server is
> running but doesn't if a server is running already.

------------------------------------------------------------------------------
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