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
I would like to set my $env.EDITOR so that it will cause this command to be run: code --wait. That's one command where argv is ['code', '--wait']. I tried these two things:
The first one says it wants a string, and got a list<string>, which makes sense. The second one says there's no command called code --wait. So I think it's trying to find a binary literally named code --wait in the path. Is there some way to do this, that I'm missing?
How to reproduce
Run let-env EDITOR = [ "code", "--wait" ] or let-env EDITOR = "code --wait"
Run config nu
See error
Expected behavior
Open code and pass in an argument --wait. Lots of editors need some sort of switch (I used to use emacsclient -t, because emacsclient by itself would fail if the emacs daemon isn't running).
The question is which tool is going to execute the contents of that EDITOR environment variable? If it's an external command, e.g , git, then the value must be visible in the OS (process) environment, and must therefore be a simple string. Nushell allows environment variables to have other types (such as turning PATH into a list of directories), but that's only for use within Nushell.
You could create a shell script (bash, sh or, ps1) to invoke your editor with arguments, such as code --wait $*, put it in your path and point the environment variable at that. ( $* pulls any extra arguments the tool provides, such as file names, into shell script. Powershell syntax might differ....)
While it's true that I could create a shell script that contains #!/bin/sh and code --wait $*, that's a workaround. The tool that I'm referring to that will execute the contents of the EDITOR environment variable is nushell itself. That's why I specified config nu or config env as commands that reproduce the problem.
Is there a way I can do this using the same sort of processing that happens when modifying the PATH? Internally, nushell keeps track of PATH as list<string> but its child processes of course see the PATH just as they would in any other shell. In other words, nushell treats PATH in a strongly-typed way but stringifies it for spawned processes, right?
I tried defining a Nushell alias, e.g, alias xyz = code --wait, and let-env EDITOR = "xyz", but got this error when I tried to invoke it.
〉config env
Error: nu::shell::external_command (link)
× External command failed
╭─[entry #5:1:1]
1 │ config env
· ─────┬────
· ╰── executable 'xyz' was not found
╰────
help: No such file or directory (os error 2)
So I think the external shell script hack is the only workaround currently available.
If there is an enhancement to allow EDITOR to be an array, I'd prefer a string value also be supported, the convention of environment variables as strings is pretty well ingrained.
Nushell already has provisions for converting between its internal representation of environment variables and external processes. Here's some code copied right from the auto-generated env.nu:
# Specifies how environment variables are:
# - converted from a string to a value on Nushell startup (from_string)
# - converted from a value back to a string when running external commands (to_string)
# Note: The conversions happen *after* config.nu is loaded
let-env ENV_CONVERSIONS = {
"PATH": {
from_string: { |s| $s | split row (char esep) | path expand -n }
to_string: { |v| $v | path expand -n | str join (char esep) }
}
"Path": {
from_string: { |s| $s | split row (char esep) | path expand -n }
to_string: { |v| $v | path expand -n | str join (char esep) }
}
}
I will dig into the code shortly to see if I can make the config command behave in the same way that Nushell handles the PATH.
I think the problem lies in the places where we read EDITOR and VISUAL to decide what to launch. I think it is easier to make that tolerant than to include an extra env conversion (which could effectively also only either pass a list or a string to that call site)
Activity
bobhy commentedon Feb 12, 2023
The question is which tool is going to execute the contents of that EDITOR environment variable? If it's an external command, e.g ,
git, then the value must be visible in the OS (process) environment, and must therefore be a simple string. Nushell allows environment variables to have other types (such as turning PATH into a list of directories), but that's only for use within Nushell.You could create a shell script (bash, sh or, ps1) to invoke your editor with arguments, such as
code --wait $*, put it in your path and point the environment variable at that. ($*pulls any extra arguments the tool provides, such as file names, into shell script. Powershell syntax might differ....)hut8 commentedon Feb 12, 2023
While it's true that I could create a shell script that contains
#!/bin/shandcode --wait $*, that's a workaround. The tool that I'm referring to that will execute the contents of the EDITOR environment variable isnushellitself. That's why I specifiedconfig nuorconfig envas commands that reproduce the problem.Is there a way I can do this using the same sort of processing that happens when modifying the PATH? Internally, nushell keeps track of PATH as
list<string>but its child processes of course see the PATH just as they would in any other shell. In other words, nushell treats PATH in a strongly-typed way but stringifies it for spawned processes, right?bobhy commentedon Feb 12, 2023
I tried defining a Nushell alias, e.g,
alias xyz = code --wait, andlet-env EDITOR = "xyz", but got this error when I tried to invoke it.So I think the external shell script hack is the only workaround currently available.
If there is an enhancement to allow EDITOR to be an array, I'd prefer a string value also be supported, the convention of environment variables as strings is pretty well ingrained.
hut8 commentedon Feb 12, 2023
Nushell already has provisions for converting between its internal representation of environment variables and external processes. Here's some code copied right from the auto-generated
env.nu:I will dig into the code shortly to see if I can make the
configcommand behave in the same way that Nushell handles the PATH.sholderbach commentedon Feb 13, 2023
I think the problem lies in the places where we read
EDITORandVISUALto decide what to launch. I think it is easier to make that tolerant than to include an extra env conversion (which could effectively also only either pass a list or a string to that call site)allow for arguments in EDITOR and VISUAL env vars (#8105)