gitui icon indicating copy to clipboard operation
gitui copied to clipboard

Vim is not available as external editor on windows

Open ShrykeWindgrace opened this issue 3 years ago • 7 comments

Thanks for gitui, it makes my daily life easier=)

There is, however, one thing that seems break my current flow - I can not launch vim from within gitui.

Describe the bug Vim is not available as external editor

To Reproduce Steps to reproduce the behavior:

  1. Navigate to a repo with modified files, run gitui
  2. Chose a file with modifications
  3. Hit 'e' button to edit this file
  4. A "popup" appears:
failed to launch editor:
"vim": program not found

Same bug observed when trying to '^e'dit commit message in external editor.

Expected behavior A vim instance with selected file loaded.

Context (please complete the following information):

  • OS/Distro + Version: win10 (build 21H2-19044.1889)
  • GitUI Version 0.21.0
  • Running in WindowsTerminal and pwsh-7.2.6
  • both vim and gitui are installed via chocolatey

Additional context vim is present in path:

PS1> where.exe vim
C:\Windows\vim.bat

and git is configured to use vim

git config  -l | rg editor
core.editor=vim

ShrykeWindgrace avatar Sep 07 '22 17:09 ShrykeWindgrace

need windows user support for this

extrawurst avatar Sep 18 '22 13:09 extrawurst

I did a bit of digging

  • "real" vim in my $PATH is, in fact, a bat script:
PS> (Get-Command vim).Name
vim.bat
  • there is a %PATHEXT% ($env:PATHEXT in pwsh) env variable that specifies the list of extensions to test if the command's extension is not provided. (see also https://learn.microsoft.com/en-us/previous-versions/cc723564(v=technet.10)#command-search-sequence and https://stackoverflow.com/a/1653492/3206165)
  • For some reason the implementation in rust (I suppose the guilty party should be somewhere around externaleditor.rs:115) does not do these extension checks and only tries to run the provided executable as-is.

I see the following solutions:

  • (workaround) explicitly provide extension; might lead to bugs if one uses git's config in a cross-platform (or cross-installation) manner (that's my case, unfortunately)
  • fix behavior of the library responsible for running external commands; that would be waaaay out of my depth, I can't write a helloworld in rust
  • bikeshed a test in gitui "if the editor command has no extension and we are on windows, then try with the extensions form that env var..."
  • some other option I might have missed?

ShrykeWindgrace avatar Sep 20 '22 12:09 ShrykeWindgrace

Aha, it appears that things are not that easy upstream...

https://github.com/rust-lang/rust/issues/37519

https://doc.rust-lang.org/src/std/process.rs.html#540-543

https://github.com/rust-lang/rust/pull/37381

... and all the way down the rabbit whole...

ShrykeWindgrace avatar Sep 20 '22 12:09 ShrykeWindgrace

vs code is also not usable because of this. I have mine editor in git config:

git config -l|?{$_ -like '*edit*'}
core.editor=code --wait

and

gcm code

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Application     code.cmd                                           0.0.0.0    C:\Program Files\Microsoft VS Code\bin\code.cmd

metasong avatar Nov 28 '22 22:11 metasong

investigating this.

  • the issue is trying to run a command script (.bat or .cmd) but only giving the root name - vim, code etc.
  • works fine with vim.bat or code.cmd
  • not an issue with gitui, a simple 5 line test prog has the same issue
  • importantly git on windows works with editor set to 'vim'. So this is a backwards step as far as a regular git user on windows is concerned

Thr std::Process code is really very broken, making all sorts of odd assumptions trying to make things work 'by magic'. I will file a bug but dont hold your breath.

I think I can come up with a solution - will update here

pm100 avatar Apr 08 '23 16:04 pm100

This issue has been automatically marked as stale because it has not had any activity half a year. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Oct 15 '23 14:10 stale[bot]