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.
-
Right now, es doesn't know or care about the
PWD
environment 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
PWD
variable causes wrong behavior (specifically, terminal cwd-syncing behavior like this, though I also found this fish issue where badPWD
s 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:PWD
againstcwd
(i.e., the return value fromgetcwd(3)
). If the two point to the same inode,chdir(3)
toPWD
. Otherwise, setPWD
tocwd
.cd
time, setPWD
to the newcwd
.Note that
PWD
only makes sense if it's an absolute pathname.PWD
need not, however, be a canonical pathname, and the behavior described above makes the shell respect it ifPWD
includes symlinks.It's reasonably easy to hack an approximation of this into
.esrc
with 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/pwd
duringcd
. It would be pretty simple to either define a$&pwd
primitive, or as a more general option, add a-a
flag for$&access
, such thataccess -1a path
canonicalizespath
when printing it. Thenpwd
could either be defined asecho <=$&pwd
orecho <={access -1a .}
, respectively.Second, this version doesn't actually sync
PWD
with 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-loop
and%interactive-loop
in.esrc
to setPWD
right at the start, I suppose.There's also the matter of "if
PWD
is equivalent tocwd
modulo 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
:PWD
all into C: add aninitwd()
inmain.c
which handles the startup behavior and addPWD
-setting logic within$&cd
.initwd()
inmain.c
, and provide a$&pwd
primitive 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
cwd
in for my own convenience until I realized thatPWD
is 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