Skip to content

EDITOR cannot contain arguments #8051

Closed

Description

@hut8

Describe the bug

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:

let-env EDITOR = [ "code", "--wait" ]
# and
let-env EDITOR = "code --wait"

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

  1. Run let-env EDITOR = [ "code", "--wait" ] or let-env EDITOR = "code --wait"
  2. Run config nu
  3. 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).

Screenshots

No response

Configuration

key value
version 0.74.0
branch makepkg
commit_hash 9a56665
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.66.0 (69f9c33d7 2022-12-12) (Arch Linux rust 1:1.66.0-1)
cargo_version cargo 1.66.0
pkg_version 0.74.0
build_time 2023-01-10 22:53:04 +00:00
build_rust_channel release
features database, dataframe, default, trash, which, zip
installed_plugins

Additional context

No response

Activity

  1. bobhy commented on Feb 12, 2023

    @bobhy
    Contributor

    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....)

  2. hut8 commented on Feb 12, 2023

    @hut8
    Author

    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?

  3. added
    category:enhancement
    on Feb 12, 2023
  4. bobhy commented on Feb 12, 2023

    @bobhy
    Contributor

    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.

  5. hut8 commented on Feb 12, 2023

    @hut8
    Author

    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.

  6. sholderbach commented on Feb 13, 2023

    @sholderbach
    Member

    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)

  7. added a commit that references this issue on Feb 26, 2023
    9bbb971
  8. added this to the v0.77.0 milestone on Feb 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    category:enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions