elvish
elvish copied to clipboard
Elvish should not resolve symlinks when changing directory
This is extremely disruptive, when you need to launch a program with certain cwd, but elvish keeps implicitly changing it. Or a simple fact that cd dir; cd ..
doesnt cancel out.
I disagree. I much prefer having $pwd
reflect the current physical directory, independent of the history of how you got there. I think using the symlink from earlier invocations of cd
is a misfeature of other shells that I'd rather be without. But I can sympathise: Once you have gotten used to this (mis)feature, it feels disruptive to have it gone.
That said, it would be useful to have an easy way to go back to the previous directory. Issue #1043 is one step towards achieving that, and more. Personally, I have hacked the location mechanism to keep a history of recently visited directories, updating the list of pinned locations from within a before-readline
hook. With suitable keybindings, it is a mere couple of key presses to move back to the previous directory – in my case, M-g (bound to edit:location:start
) followed by down arrow and return.
@hanche please note that a full directory history implementation is available in my dir.org module :) With this I can use Alt-left/right to navigate among directories (works smartly so you can still use them to move the cursor by word when the command line is not empty).
About the original question: I also prefer the directory to be expanded to its true value. But I can see how this could be a desirable option for people used to the behavior in other shells (TIL about the -P
/ -L
options to cd
available in bash, ksh, zsh). To be honest, with the dir
module and location mode, I almost never use cd
anymore ;)
This is a highly contentious topic and it's impossible to make everyone happy. When you say, @SolitudeSF, "launch a program with certain cwd" it's not clear if this is solely about being able to cd
to a specific directory and cd
back to the previous directory. Or, do you expect the program being launched to see the logical path as if the symlink was not converted to a physical path? The former is possible, the latter is impossible. And therein lies the problem.
I find it helps to use concrete examples. Assume the CWD is the physical path /a/b and it contains a symlink s => /usr/local/share. Consider the sequence cd s
, vim some-file
, cd ..
. We can certainly arrange for the cd ..
to return to /a/b rather than /usr/local. But what if you do :e ../another-file
inside vim? It will open /usr/local/another-file not /a/b/another-file. There is no way (or at least no established convention) by which the relative path inside vim will respect the /a/b/s logical path. If elvish were to use logical paths when executing cd
it can result in confusion when external commands use relative paths. For that matter, what should cd s; path-abs some-file
output? Should it be /a/b/s/some-file or /usr/local/share/some-file? Should builtins other than cd
behave the same or different than external commands in this regard?
There are arguments for and against cd
using physical or logical paths. I prefer that cd
through a symlink not hide the fact a symlink was traversed. That is, that cd
use physical paths, the current behavior. But, there should be an easy to use mechanism to do the equivalent of orig_wd = $pwd; cd s; some-command; cd $orig_wd
. Resolving issue #1043 is one way to address that need.