PSReadLine icon indicating copy to clipboard operation
PSReadLine copied to clipboard

Consider using a default editor for the `ViEditVisually` function and / or issue a warning if the `$env:VISUAL` / `$env:EDITOR` value is invalid.

Open mklement0 opened this issue 1 year ago • 0 comments

Prerequisites

  • [X] Write a descriptive title.

Description of the new feature/enhancement

Currently, invoking the ViEditVisually function fails with no feedback other than a beep:

  • if neither $env:VISUAL no $env:EDITOR are defined.
  • If either variable exists, but contains an invalid value (notably including the case where options are part of the value - see https://github.com/PowerShell/PowerShell/issues/21525).

Consider modifying the behavior as follows, which would not only be more user-friendly in general, but also align with the behavior of other utilities, such as bash and git:

  • Use a default editor if neither $env:VISUAL no $env:EDITOR are defined - and issue a warning if it cannot be found.

    • A possible candidate on Unix-like platform is vi (this is what git does, though on some platforms it has gedit as the compiled-in default)
    • On Windows, Notepad would do as a guaranteed-to-be-present option, though that would require invocation via Start-Process -Wait (or equivalent) to ensure synchronous execution. Note that if a given machine has Git for Windows installed, nano and vim are present (but not in $env:PATH), via $env:ProgramFiles\Git\usr\bin\nano.exe and $env:ProgramFiles\Git\usr\bin\vim.exe
  • Issue a warning if the effective $env:VISUAL / $env:EDITOR value isn't invalid; ditto, should the decision be made not to implement use of a default editor and neither $env:VISUAL nor $env:EDITOR is defined.

Proposed technical implementation details (optional)

No response

mklement0 avatar Apr 25 '24 18:04 mklement0