Skip to content

While starting nu, force PWD to be current working directory - #5751

Merged
fdncred merged 3 commits into
nushell:mainfrom
WindSoilder:fix_init_cwd
Jun 10, 2022
Merged

fdncred merged 3 commits into
nushell:mainfrom
WindSoilder:fix_init_cwd

Conversation

@WindSoilder

@WindSoilder WindSoilder commented Jun 10, 2022 •

Copy link
Copy Markdown
Contributor

Description

Fixes: #5050

I don't change merge_delta() because it seems hard to change, especially we have some overlays and some stacks.

Instead, The issue seems only happens during start nu, so maybe it's just enough to change gather_parent_env_vars function.

The reason to use init_cwd:

While gathering parent env vars, the parent PWD may not be the same as current working directory.
Consider to the following command as the case (assume we execute command inside /tmp):

tmux split-window -v -c "#{pane_current_path}"

Here nu execute external command tmux, and tmux starts a new nushell, with init_cwd value "#{pane_current_path}".

But at the same time PWD still remains to be /tmp.

In this scenario, the new nushell's PWD should be "#{pane_current_path}" rather init_cwd.

Tests

Make sure you've run and fixed any issues with these commands:

  • cargo fmt --all -- --check to check standard code formatting (cargo fmt --all applies these changes)
  • cargo clippy --workspace --features=extra -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect to check that you're using the standard code style
  • cargo test --workspace --features=extra to check that all the tests pass

Comment thread crates/nu-cli/src/util.rs Resolved
Comment thread crates/nu-cli/src/util.rs Resolved
@fdncred

fdncred commented Jun 10, 2022

Copy link
Copy Markdown
Contributor

are we ready to land this?

@WindSoilder

Copy link
Copy Markdown
Contributor Author

I think it's better to see if @kubouch has more comment for it :)

@kubouch

kubouch commented Jun 10, 2022

Copy link
Copy Markdown
Contributor

Looks good @WindSoilder. Have you verified it solves the issue with the tmux not changing PWD? (I don't know how we could add a test for that...)

@WindSoilder

Copy link
Copy Markdown
Contributor Author

yeah, I've tested the following commands mentioned in the issue:

  • tmux split-window -v -c "#{pane_current_path}"
  • tmux new-window -a -c "#{pane_current_path}"
  • tmux attach-session -c -t

But I can't reproduce the issue inside vscode, so I haven't test for that

@fdncred

fdncred commented Jun 10, 2022

Copy link
Copy Markdown
Contributor

nice! let's try it out. thanks!

@fdncred
fdncred merged commit c5cb369 into nushell:main Jun 10, 2022
@WindSoilder
WindSoilder deleted the fix_init_cwd branch June 11, 2022 07:05
fennewald pushed a commit to fennewald/nushell that referenced this pull request Jun 27, 2022
…#5751)

* fix current working directory during start

* fix tests

* always set PWD to current_dir
@fdncred fdncred mentioned this pull request Mar 4, 2026
2 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nushell doesn't play nice with "current directory"

3 participants