nushell/crates/nu-command/src/core_commands
Jakub Žádník 74dcd91cc3
Use only $nu.env.PWD for getting the current directory (#587)
* Use only $nu.env.PWD for getting current directory

Because setting and reading to/from std::env changes the global state
shich is problematic if we call `cd` from multiple threads (e.g., in a
`par-each` block).

With this change, when engine-q starts, it will either inherit existing
PWD env var, or create a new one from `std::env::current_dir()`.
Otherwise, everything that needs the current directory will get it from
`$nu.env.PWD`. Each spawned external command will get its current
directory per-process which should be thread-safe.

One thing left to do is to patch nu-path for this as well since it uses
`std::env::current_dir()` in its expansions.

* Rename nu-path functions

*_with is not *_relative which should be more descriptive and frees
"with" for use in a followup commit.

* Clone stack every each iter; Fix some commands

Cloning the stack each iteration of `each` makes sure we're not reusing
PWD between iterations.

Some fixes in commands to make them use the new PWD.

* Post-rebase cleanup, fmt, clippy

* Change back _relative to _with in nu-path funcs

Didn't use the idea I had for the new "_with".

* Remove leftover current_dir from rebase

* Add cwd sync at merge_delta()

This makes sure the parser and completer always have up-to-date cwd.

* Always pass absolute path to glob in ls

* Do not allow PWD a relative path; Allow recovery

Makes it possible to recover PWD by proceeding with the REPL cycle.

* Clone stack in each also for byte/string stream

* (WIP) Start moving env variables to engine state

* (WIP) Move env vars to engine state (ugly)

Quick and dirty code.

* (WIP) Remove unused mut and args; Fmt

* (WIP) Fix dataframe tests

* (WIP) Fix missing args after rebase

* (WIP) Clone only env vars, not the whole stack

* (WIP) Add env var clone to `for` loop as well

* Minor edits

* Refactor merge_delta() to include stack merging.

Less error-prone than doing it manually.

* Clone env for each `update` command iteration

* Mark env var hidden only when found in eng. state

* Fix clippt warnings

* Add TODO about env var reading

* Do not clone empty environment in loops

* Remove extra cwd collection

* Split current_dir() into str and path; Fix autocd

* Make completions respect PWD env var
2022-01-05 09:30:34 +11:00
..
alias.rs Category option for signature (#343) 2021-11-17 17:22:37 +13:00
debug.rs Make config default if broken (#482) 2021-12-13 14:16:51 +11:00
def.rs Category option for signature (#343) 2021-11-17 17:22:37 +13:00
describe.rs Let describe know about binary (#662) 2022-01-04 14:05:24 +11:00
do_.rs Add missing flags to existing commands (#565) 2021-12-24 08:41:29 +11:00
echo.rs Add string stream and binary stream, add text decoding (#570) 2021-12-24 18:22:11 +11:00
export.rs Category option for signature (#343) 2021-11-17 17:22:37 +13:00
export_def.rs Category option for signature (#343) 2021-11-17 17:22:37 +13:00
export_env.rs Category option for signature (#343) 2021-11-17 17:22:37 +13:00
for_.rs Use only $nu.env.PWD for getting the current directory (#587) 2022-01-05 09:30:34 +11:00
help.rs Fix 'help commands'; Add 'is_custom' column (#420) 2021-12-03 20:45:29 +02:00
hide.rs Use only $nu.env.PWD for getting the current directory (#587) 2022-01-05 09:30:34 +11:00
history.rs Decode escaped newlines in history command (#592) 2021-12-27 10:11:08 +11:00
if_.rs A few help cleanups (#372) 2021-11-28 07:16:20 +13:00
ignore.rs Ported ignore command to engine-q (#621) 2021-12-30 15:54:33 +11:00
let_.rs A few help cleanups (#372) 2021-11-28 07:16:20 +13:00
metadata.rs Add metadata command (#569) 2021-12-24 11:16:50 +11:00
mod.rs Ported ignore command to engine-q (#621) 2021-12-30 15:54:33 +11:00
module.rs Category option for signature (#343) 2021-11-17 17:22:37 +13:00
register.rs Plugin option for shell (#517) 2021-12-18 12:13:56 -06:00
source.rs Category option for signature (#343) 2021-11-17 17:22:37 +13:00
use_.rs Remove Span::unknown (#525) 2021-12-19 18:46:13 +11:00
version.rs Remove Span::unknown (#525) 2021-12-19 18:46:13 +11:00