Replies: 3 comments 1 reply
-
|
Hmmm... For many years, I used some customizations (as es functions) that provided several things, including keeping PWD up-to-date with every invocation of "cd". Here's what I had then: That's a little involved, but it avoids invoking /bin/pwd unless there's messiness involving a reference to "..". As keeping PWD up-to-date with subshell invocations, I found this in my old setup: It's been awhile, but I think that snippet guaranteed a lot of stuff got re-updated after pushing an interactive subshell. |
Beta Was this translation helpful? Give feedback.
-
|
My instinct is 'curses be upon all standard shell behaviour, I'm already a masochist if I'm using es', but if this will legitimately trip up users and it's easy to support then... sure? FWIW, I also have a 'cd' which tracks the current directory, but doesn't require `pwd: (snippet of my cd which also does other weird things; may or may not make sense on its own) |
Beta Was this translation helpful? Give feedback.
-
|
At the moment, I'm leaning towards just having a |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Right now, es doesn't know or care about the
PWDenvironment variable. This violates the POSIX standard, but es doesn't really care about POSIX compatibility, and it seems like for the most part, things "just work" withoutPWD.However, I recently ran into a case where a missing or incorrect
PWDvariable causes wrong behavior (specifically, terminal cwd-syncing behavior like this, though I also found this fish issue where badPWDs caused people a lot of other problems). So I started looking into it. Based on a couple other shells, the right behavior seems to be:PWDagainstcwd(i.e., the return value fromgetcwd(3)). If the two point to the same inode,chdir(3)toPWD. Otherwise, setPWDtocwd.cdtime, setPWDto the newcwd.Note that
PWDonly makes sense if it's an absolute pathname.PWDneed not, however, be a canonical pathname, and the behavior described above makes the shell respect it ifPWDincludes symlinks.It's reasonably easy to hack an approximation of this into
.esrcwith something like this:But I find this lacking in a couple ways. First, I really don't like depending on an external binary like
/bin/pwdduringcd. It would be pretty simple to either define a$&pwdprimitive, or as a more general option, add a-aflag for$&access, such thataccess -1a pathcanonicalizespathwhen printing it. Thenpwdcould either be defined asecho <=$&pwdorecho <={access -1a .}, respectively.Second, this version doesn't actually sync
PWDwith the current directory at (non-login) shell startup, and there's really no facility to do something like that. You could hack up a new%batch-loopand%interactive-loopin.esrcto setPWDright at the start, I suppose.There's also the matter of "if
PWDis equivalent tocwdmodulo symlinks, keep the current value", but I can't even picture a way to do that in es script.So, a couple alternate ideas, in decreasing order of special-casing
PWD:PWDall into C: add aninitwd()inmain.cwhich handles the startup behavior and addPWD-setting logic within$&cd.initwd()inmain.c, and provide a$&pwdprimitive that can be called withincd.These first two options can provide behavior that perfectly matches the "common" shell path, especially with respect to symbolic links. The following options don't, in my mind, provide a clear way to handle symlinks well.
PWD, like a shell-startup hook and a canonicalization flag for$&access.The last two options don't handle symlinks quite right, in the case where the absolute path from
getcwd()may not be the "canonical" path. One of the big fights in the mailing list was on this exact topic :) Based on my understanding of how it works, the typical shell behavior is pretty okay, but of course giving the user the ability to write their own preference into the shell would be nice.I'm curious how people feel about all this. I was happy just hacking a
cwdin for my own convenience until I realized thatPWDis actually kind of load bearing, so it deserves some thinking about what the default behavior should be out of the box.Beta Was this translation helpful? Give feedback.
All reactions