jesseduffield / jesseduffield/lazygit

nvim-remote edit preset uses POSIX shell syntax on Windows, breaking under cmd.exe

Open
#5,696 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Go
Stars
82.4k
Forks
3k
Avg merge
2d 18h
Merged PRs (30d)
19

Description

### Describe the bug

The `nvim-remote` edit preset emits a command template that uses POSIX shell syntax (`[ -z "$NVIM" ] && (...) || (...)`) for any shell that isn't fish or nushell. On Windows, lazygit's default shell is `cmd` (see `pkg/commands/oscommands/os_windows.go#L13`), and `cmd.exe` cannot parse this syntax — `[`, `$NVIM`, and the `&& / ||` chaining all misbehave. The edit keybinding therefore fails when the preset is selected on Windows.

### To Reproduce

1. On Windows (no WSL), use a Neovim integration that sets `os.editPreset: nvim-remote` — e.g. snacks.nvim defaults to this (`lua/snacks/lazygit.lua#L37`).
2. Open a file in Neovim, launch lazygit from inside it (so `$NVIM` is set).
3. Stage or unstage a file, press `e` to edit.
4. cmd.exe receives `[ -z "$NVIM" ] && (nvim -- "file") || (nvim --server "$NVIM" --remote-send "q" && nvim --server "$NVIM" --remote-tab "file")` and fails to execute it.

### Expected behavior

Either:
- the `nvim-remote` preset includes a Windows/cmd branch that uses `if defined NVIM` + `%NVIM%`, or
- the docs make clear that `nvim-remote` is POSIX-shell-only and Windows users should pick a different preset or supply `os.edit` explicitly.

### Relevant source

Preset definition: https://github.com/jesseduffield/lazygit/blob/master/pkg/config/editor_presets.go#L56-L86

The `else` branch (lines 67-71) assumes a POSIX shell; on Windows `Platform.Shell` is `cmd` and there is no matching branch.

### Version info

* lazygit version: latest `master` (issue is in the source on `master` as of writing)

### Terminal info

Any Windows terminal — the issue is the shell template, not the terminal emulator.

### Additional context

A sketch of what a cmd-compatible template might look like (untested, posted for discussion only — I don't have a Windows environment to validate cmd quoting and `%NVIM%` expansion semantics inside parenthesised blocks):

\`\`\`
if defined NVIM (nvim --server "%NVIM%" --remote-send "q" ^&^& nvim --server "%NVIM%" --remote-tab {{filename}}) else (nvim -- {{filename}})
\`\`\`

The trigger for many users today is [snacks.nvim](https://github.com/folke/snacks.nvim), which sets `editPreset = "nvim-remote"` as a default. The known workaround is to override `editPreset = ""` and supply a manual `edit` command with `shell: bash` — viable only if the user has Git Bash on PATH.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.