You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
nu script doesn't have access to config functions #5544
Technically, there is a config loaded because I used it with the --table-mode functionality. You can see it in crates/nu-cli/src/commands.rs in the evaluate_commands() function. It's just that this all happens in a separate part of code where the "real" config doesn't load.
One argument against loading config by default when running scripts is portability. If you rely on implicit loading of your local config and send the script to your friend's machine, the friend won't be able to run it.
We already have --config and --env-config flags to nu so maybe we could change it that when you specify them, it would load the config but otherwise not?
powershell loads the config / profile.ps1 when executing a command.
What does bash do?
I suspect if a script depends on specific modules or functions to run then that will be tricky either way, and not loading the config doesn't really help.
I think the way signature parsing works in Nushell is that either you have a flag --config or a --config file.nu with a required value. So for a start we could just go for always requiring a value after --config.
Thanks @WindSoilder , nu --config my/config.nu -c 'custom-command' works on the latest main, I have just tested it on my mac. Feel free to reopen if it doesn't work for you
Activity
fdncred commentedon May 14, 2022
I'm wondering if nushell is loading the config.nu and env.nu when running a nu script like this.
kubouch commentedon May 15, 2022
Yeah, when you run a script like
nu script.nu, it won't read the config.WindSoilder commentedon May 20, 2022
Is it ok to load config whatever using nu like
nu script.nuandnu -c ls?fdncred commentedon May 20, 2022
Technically, there is a config loaded because I used it with the
--table-modefunctionality. You can see it in crates/nu-cli/src/commands.rs in the evaluate_commands() function. It's just that this all happens in a separate part of code where the "real" config doesn't load.I'm not sure we want to load the config or not.
WindSoilder commentedon May 20, 2022
Hmm... It seems that only you provide
--table-mode, the config will be loaded.For the issue case, I think it's going to
evaluate_file, which is not loading config file too.I'm not sure either, If we always load the config, I don't know if there is a potential case we need to handle.
danjenson commentedon May 21, 2022
Why not make it an opt-in when running scripts or provide a -l,--library command that loads functions from a given file?
kubouch commentedon May 21, 2022
One argument against loading config by default when running scripts is portability. If you rely on implicit loading of your local config and send the script to your friend's machine, the friend won't be able to run it.
We already have
--configand--env-configflags tonuso maybe we could change it that when you specify them, it would load the config but otherwise not?DejayRezme commentedon May 21, 2022
powershell loads the config / profile.ps1 when executing a command.
What does bash do?
I suspect if a script depends on specific modules or functions to run then that will be tricky either way, and not loading the config doesn't really help.
danjenson commentedon May 21, 2022
I like that idea @kubouch , and it seems natural -- I tried specifying those next to see if they worked
fdncred commentedon May 21, 2022
ya, I think
--configand--env-configis a good compromise too. Who wants to PR that? LOLWindSoilder commentedon May 22, 2022
Hmm... Is that means the following?
--configis specified without value, load default config--configis specified with value, like--config a.nu, loada.nuas config file, but don't load default config.--configis not provided, don't load config?kubouch commentedon May 22, 2022
I think the way signature parsing works in Nushell is that either you have a flag
--configor a--config file.nuwith a required value. So for a start we could just go for always requiring a value after--config.hustcer commentedon May 23, 2022
Thanks @WindSoilder ,
nu --config my/config.nu -c 'custom-command'works on the latest main, I have just tested it on my mac. Feel free to reopen if it doesn't work for youkubouch commentedon Jul 14, 2022
So the solution here is to pass a
--configflag manually.