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

Comments

Projects
None yet
9 participants
@foonathan
Copy link

foonathan commented Feb 12, 2019

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

This comment has been minimized.

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?

@heppu

This comment has been minimized.

Copy link

heppu commented Feb 15, 2019

Any update on this one?

@ridiculousfish

This comment has been minimized.

Copy link
Member

ridiculousfish commented Feb 18, 2019

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

This comment has been minimized.

Copy link

Maxr1998 commented Feb 18, 2019

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

Copy link

AlekSi commented Feb 18, 2019

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

@ridiculousfish

This comment has been minimized.

Copy link
Member

ridiculousfish commented Feb 18, 2019

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

ridiculousfish added a commit that referenced this issue Feb 18, 2019

@ridiculousfish ridiculousfish modified the milestones: fish 3.1.0, 3.0.2 Feb 18, 2019

@ridiculousfish

This comment has been minimized.

Copy link
Member

ridiculousfish commented Feb 18, 2019

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

@hauleth

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

Copy link

Maxr1998 commented Feb 18, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.