mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-11 20:36:03 +02:00
Fish shell does not support "&&" and "||" operators like POSIX-compatible shells. Instead, it uses a different syntax structure based on begin/end and if/else. This caused existing lazygit nvim-remote integration templates to break when fish was the user's default shell. This commit adds explicit fish shell detection using the FISH_VERSION environment variable, and provides fish-compatible templates that correctly handle launching Neovim or sending remote commands via $NVIM. Fixes behavior where edits would not open in a new Neovim tab or line navigation would fail when $NVIM was set. Ensures smoother editing experience for users running fish shell (supported since Nov 2012 with FISH_VERSION).
126 lines
3.4 KiB
Go
126 lines
3.4 KiB
Go
package config
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestGetEditTemplate(t *testing.T) {
|
|
trueVal := true
|
|
|
|
scenarios := []struct {
|
|
name string
|
|
osConfig *OSConfig
|
|
guessDefaultEditor func() string
|
|
expectedEditTemplate string
|
|
expectedEditAtLineTemplate string
|
|
expectedEditAtLineAndWaitTemplate string
|
|
expectedSuspend bool
|
|
}{
|
|
{
|
|
"Default template is vim",
|
|
&OSConfig{},
|
|
func() string { return "" },
|
|
"vim -- {{filename}}",
|
|
"vim +{{line}} -- {{filename}}",
|
|
"vim +{{line}} -- {{filename}}",
|
|
true,
|
|
},
|
|
{
|
|
"Setting a preset",
|
|
&OSConfig{
|
|
EditPreset: "vscode",
|
|
},
|
|
func() string { return "" },
|
|
"code --reuse-window -- {{filename}}",
|
|
"code --reuse-window --goto -- {{filename}}:{{line}}",
|
|
"code --reuse-window --goto --wait -- {{filename}}:{{line}}",
|
|
false,
|
|
},
|
|
{
|
|
"Setting a preset wins over guessed editor",
|
|
&OSConfig{
|
|
EditPreset: "vscode",
|
|
},
|
|
func() string { return "nano" },
|
|
"code --reuse-window -- {{filename}}",
|
|
"code --reuse-window --goto -- {{filename}}:{{line}}",
|
|
"code --reuse-window --goto --wait -- {{filename}}:{{line}}",
|
|
false,
|
|
},
|
|
{
|
|
"Overriding a preset with explicit config (edit)",
|
|
&OSConfig{
|
|
EditPreset: "vscode",
|
|
Edit: "myeditor {{filename}}",
|
|
SuspendOnEdit: &trueVal,
|
|
},
|
|
func() string { return "" },
|
|
"myeditor {{filename}}",
|
|
"code --reuse-window --goto -- {{filename}}:{{line}}",
|
|
"code --reuse-window --goto --wait -- {{filename}}:{{line}}",
|
|
true,
|
|
},
|
|
{
|
|
"Overriding a preset with explicit config (edit at line)",
|
|
&OSConfig{
|
|
EditPreset: "vscode",
|
|
EditAtLine: "myeditor --line={{line}} {{filename}}",
|
|
SuspendOnEdit: &trueVal,
|
|
},
|
|
func() string { return "" },
|
|
"code --reuse-window -- {{filename}}",
|
|
"myeditor --line={{line}} {{filename}}",
|
|
"code --reuse-window --goto --wait -- {{filename}}:{{line}}",
|
|
true,
|
|
},
|
|
{
|
|
"Overriding a preset with explicit config (edit at line and wait)",
|
|
&OSConfig{
|
|
EditPreset: "vscode",
|
|
EditAtLineAndWait: "myeditor --line={{line}} -w {{filename}}",
|
|
SuspendOnEdit: &trueVal,
|
|
},
|
|
func() string { return "" },
|
|
"code --reuse-window -- {{filename}}",
|
|
"code --reuse-window --goto -- {{filename}}:{{line}}",
|
|
"myeditor --line={{line}} -w {{filename}}",
|
|
true,
|
|
},
|
|
{
|
|
"Unknown preset name",
|
|
&OSConfig{
|
|
EditPreset: "thisPresetDoesNotExist",
|
|
},
|
|
func() string { return "" },
|
|
"vim -- {{filename}}",
|
|
"vim +{{line}} -- {{filename}}",
|
|
"vim +{{line}} -- {{filename}}",
|
|
true,
|
|
},
|
|
{
|
|
"Guessing a preset from guessed editor",
|
|
&OSConfig{},
|
|
func() string { return "emacs" },
|
|
"emacs -- {{filename}}",
|
|
"emacs +{{line}} -- {{filename}}",
|
|
"emacs +{{line}} -- {{filename}}",
|
|
true,
|
|
},
|
|
}
|
|
for _, s := range scenarios {
|
|
t.Run(s.name, func(t *testing.T) {
|
|
template, suspend := GetEditTemplate("bash", s.osConfig, s.guessDefaultEditor)
|
|
assert.Equal(t, s.expectedEditTemplate, template)
|
|
assert.Equal(t, s.expectedSuspend, suspend)
|
|
|
|
template, suspend = GetEditAtLineTemplate("bash", s.osConfig, s.guessDefaultEditor)
|
|
assert.Equal(t, s.expectedEditAtLineTemplate, template)
|
|
assert.Equal(t, s.expectedSuspend, suspend)
|
|
|
|
template = GetEditAtLineAndWaitTemplate("bash", s.osConfig, s.guessDefaultEditor)
|
|
assert.Equal(t, s.expectedEditAtLineAndWaitTemplate, template)
|
|
})
|
|
}
|
|
}
|