Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PWD not updated properly #5647

Closed
foonathan opened this issue Feb 12, 2019 · 12 comments
Closed

PWD not updated properly #5647

foonathan opened this issue Feb 12, 2019 · 12 comments
Labels
bug Something that's not working as intended regression Something that used to work, but was broken, especially between releases
Milestone

Comments

@foonathan
Copy link

Executing the following command:

env -C /tmp fish -c 'echo $PWD'

With fish version 3.0.0 this prints /tmp, as expected.

With fish version 3.0.1 this prints /home/foonathan, which is incorrect.
The same is true when disabling third-party customizations. I'm using Arch Linux and the behavior can be reproduced on all kinds of terminals.

@faho
Copy link
Member

faho commented Feb 12, 2019

@ridiculousfish: I'm assuming dfa6192 trusts $PWD, without checking that it actually represents the working directory correctly?

@faho faho added bug Something that's not working as intended regression Something that used to work, but was broken, especially between releases labels Feb 12, 2019
@faho faho added this to the fish 3.1.0 milestone Feb 12, 2019
@heppu
Copy link

heppu commented Feb 15, 2019

Any update on this one?

@ridiculousfish
Copy link
Member

Ok a timeline:

In fish 2.x, $PWD was always derived from getcwd(). This is the "always resolves symlinks" behavior.

In fish 3.0.0, $PWD was separate from getcwd() except a bug made fish discard PWD at launch. So the (accidental) behavior was "fish resolves symlinks at launch".

In fish 3.0.1 that bug was fixed, so $PWD is $PWD, and the working directory is the working directory, and fish makes no attempt to second-guess either.

In the command: env -C /tmp fish -c 'echo $PWD' what happens is that env sets the $PWD environment variable, and does NOT change the current working directory. So fish inherits a $PWD and a cwd that disagree.

fish is fine with this disagreement, while other shells apparently try to fix it, but only at launch.

It seems like what is desired it "allow PWD and cwd to disagree, except at launch, where we retain PWD only if it can be resolved to the cwd". If this env -c PWD thing is a common pattern then I suppose fish should implement that too.

@Maxr1998
Copy link

I came to this issue because I had this bug in the terminal of all JetBrains IDEs, including Android Studio, as well as in VSCode - while pwd/$PWD, and thus, the prompt were shown as my user home, ls correctly showed the contents of my project dir.

So, I guess this pattern is common enough to warrant implementing a workaround in fish as well.

@hauleth
Copy link
Contributor

hauleth commented Feb 18, 2019

This breaks almost all terminals nested in the editors. Vim and NeoVim are affected as well. And as I am heavy user of such features it is very painful problem for me.

@samhh
Copy link

samhh commented Feb 18, 2019

This also breaks at least two commonly used terminals (Alacritty, Termite) when supplying a current working directory option.

@AlekSi
Copy link

AlekSi commented Feb 18, 2019

Same problem with VSCode. There is a workaround: microsoft/vscode#68488 (comment).

@ridiculousfish
Copy link
Member

I think we need to do a 3.0.2 perhaps for this fix alone.

@ridiculousfish
Copy link
Member

Anyone experiencing this, I would appreciate testing on Integration_3.0.2 (commit 5c994b0).

@hauleth
Copy link
Contributor

hauleth commented Feb 18, 2019

Workaround for NeoVim (do not work in Vim as it has no DirChanged event):

augroup workaround_fish_issue
    autocmd!
    autocmd DirChanged * let $PWD = v:event.cwd
augroup END

@jorng
Copy link

jorng commented Feb 18, 2019

Just built Integration_3.0.2 branch on macOS, and it seems to be resolved.

fish, version 3.0.1-1-g5c994b0d

@Maxr1998
Copy link

@ridiculousfish built via aur/fish-git, and I can confirm it works fine in Android Studio.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something that's not working as intended regression Something that used to work, but was broken, especially between releases
Projects
None yet
Development

No branches or pull requests

9 participants