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
Relative file resolution (FILE_PWD) not working in configs (env.nu, config.nu) #11465
Comments
I'm kind of lost because this path will never resolve because env.nu is a file, right? > '/Users/texas/Library/Application Support/nushell/env.nu'
➜ | path join .. default_env.nu This is what it says on my system ❯ '/Users/fdncred/Library/Application Support/nushell/scripts/env.nu' | path join .. default_env.nu
/Users/fdncred/Library/Application Support/nushell/scripts/env.nu/../default_env.nu I'm also wondering if you do something like this, if it will work for you. const var = ('/Users/fdncred/Library/Application Support/nushell/scripts/' | path join default_env.nu)
source $var |
Identical to: > '/Users/texas/Library/Application Support/nushell/env.nu'
::: | path dirname | path join default_env.nu I suppose
Both the following work: # where my dotfiles are
source-env ~/.config/nushell/default_env.nu
# symlinked dir until #7371 is resolved
source-env '~/Library/Application Support/nushell/default_env.nu' I initially also tried to use Thanks for the help I'm loving it besides the 2 linked issues 🙌🏼 |
This seems to work fine. const x = ($nu.default-config-dir | path join env.nu)
source-env $x I have no issues sourcing files from $nu.default-config-dir but maybe that may be because my ❯ $env.NU_LIB_DIRS
╭───┬───────────────────────────────────────────────────╮
│ 0 │ C:\Users\username\AppData\Roaming\nushell\scripts │
│ 1 │ D:\nu_scripts │
│ 2 │ C:\Users\username\AppData\Roaming\nushell │
╰───┴───────────────────────────────────────────────────╯ A constant has to be a variable declared with const or a full path to a file. https://www.nushell.sh/book/how_nushell_code_gets_run.html and https://www.nushell.sh/book/thinking_in_nu.html go into how nushell works. piping into |
IFL I'm not communicating effectively. Starting from scratch but happy to rewrite the description too.
Nothing is loaded yet. Could that be the issue? I want to source the generated config in my user config as described in #893 (comment). My config directory happens to be symlinked as described in #7371 (comment):
I expect
Thanks! I don't know what I did wrong before but the following successfully loads: source-env ($nu.default-config-dir | path join default_env.nu)
Should I open an issue for backlog? It sounds like a couple lines at most. Rust isn't 1 of my languages but I look forward to collaborating on nushell/nushell.github.io#1189 🤘🏼 In conclusion is the import resolution and constant error expected behavior? |
I'm 50% thinking this is the issue.
nushell/crates/nu-engine/src/env.rs Lines 283 to 302 in 42bb42a
It relies on the presence of an environment variable I only found set in 2 places:
But AFAICT loading configs bypasses these pathways: nushell/crates/nu-cli/src/config_files.rs Lines 82 to 91 in 42bb42a
I don't know Rust but hopefully that's a concrete starting point! |
|
I don't get how that's possible. |
Can you confirm relative paths work in your |
I'm not really sure what you want me to test. I was just saying that this works. $env.NU_LIB_DIRS = [
($nu.config-path | path dirname | path join 'scripts')
'/Users/username/src/nu_scripts'
($nu.config-path | path dirname)
] using scripts in my config.nu that only work if nu_lib_dirs is set. # external completions
use "custom-completions/cargo/cargo-completions.nu" *
# git completions and aliases
use custom-completions/git/git-completions.nu *
use aliases/git/git-aliases.nu *
# temperature converter
use "sourced/temp.nu" *
# get_weather
use "modules/weather/get-weather.nu" get_weather |
I presented a simplified use case to test I don't understand? This errors for me OOTB (first line of file).
You're right about |
I reviewed the code again.
I was wrong
But
That's why
|
Does your example work if you use |
No not |
could've been, that was written/changed 22 months ago so a lot has changed since then |
Ping @kubouch from Git blame (I hope that's okay) 🔔 I'm not a Rust person but I'm having an issue with relative file loading that I think (based on clicking around GitHub so maybe wrong) I identified the issue in #11465 (comment). Maybe can check eventually 🙏🏼 Anyway really thank you all Nushell is wonderful! |
The parser looks for It's hard to figure out what the issue is because it's missing a minimal working example. There are no clear steps to reproduce the issue. It would be great if you could summarize the reproduction steps, starting from scratch, as simple as possible, in a 1., 2., 3., ... list such that we can quickly reproduce it. |
This was my minimal example:
I can't source any file relatively in
Result:
|
Yeah, I can reproduce it. Seems like the start file is not set correctly when evaluating the config files. This should be an easy fix: Add |
Thanks so much!!! It's a small thing but it makes breaking up my config feel messier. I added this to my list to attempt if I have time (familiar with Rust but never written any). |
Closing as duplicate of #7849. |
Fixes nushell#784, nushell#11465. Adds test that previously failed.
Fixes nushell#7849, nushell#11465. Adds test that previously failed.
<!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> Fixes #7849, #11465 based on @kubouch's suggestion in #11465 (comment). # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> Can source files relative to `env.nu` or `config.nu` like in #6150. # Tests + Formatting <!-- Don't forget to add tests that cover your changes. 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 -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> Adds test that previously failed. # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
<!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> Fixes nushell#7849, nushell#11465 based on @kubouch's suggestion in nushell#11465 (comment). # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> Can source files relative to `env.nu` or `config.nu` like in nushell#6150. # Tests + Formatting <!-- Don't forget to add tests that cover your changes. 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 -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> Adds test that previously failed. # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
<!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> Fixes nushell#7849, nushell#11465 based on @kubouch's suggestion in nushell#11465 (comment). # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> Can source files relative to `env.nu` or `config.nu` like in nushell#6150. # Tests + Formatting <!-- Don't forget to add tests that cover your changes. 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 -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> Adds test that previously failed. # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
Describe the bug
My Nu config dir is symlinked to work around #893. I'm attempting to
source-env
default_env.nu
to work around #7371. I'm seeing confusing error messages documented below.I suspect there's a bug and/or poor error message and/or misunderstanding on my part and/or all of the above ❓
First Attempt
Error
Same error with
./default_env.nu
.Context
Aside: I was surprised I couldn't pipe to
ls
.Second Attempt
Supposing it was related to symlinks I tried to
expand
it.Error
Same error with
./default_env.nu
or assigning it to aconst
.Final Attempt
I tried quoting it but it resolved relative to
$env.PWD
. That's entirely reasonable sincesource
isn't doing the expansion.Error
Same error with
'./default_env.nu'
.Info
How to reproduce
Haven't identified the root cause yet.
Expected behavior
Expect to load.
Screenshots
No response
Configuration
Additional context
No response
The text was updated successfully, but these errors were encountered: