mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-08 23:56:15 +02:00
Improve nvim-remote
mode (#3508)
- If _not_ inside a neovim session, treat as a normal nvim invocation and suspend lazygit. - If inside a neovim session: - Do not try to suspend lazygit. - Send `q` keystroke to neovim session to quit lazygit. - Send filename/line/etc. to neovim session. - **Please check if the PR fulfills these requirements** * [x] Cheatsheets are up-to-date (run `go generate ./...`) * [x] Code has been formatted (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#code-formatting)) * [ ] Tests have been added/updated (see [here](https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md) for the integration test guide) * [ ] Text is internationalised (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#internationalisation)) * [ ] Docs (specifically `docs/Config.md`) have been updated if necessary * [x] You've read through your own file changes for silly mistakes etc <!-- Be sure to name your PR with an imperative e.g. 'Add worktrees view' see https://github.com/jesseduffield/lazygit/releases/tag/v0.40.0 for examples -->
This commit is contained in:
commit
269d01233f
@ -1,5 +1,7 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
|
import "os"
|
||||||
|
|
||||||
func GetEditTemplate(osConfig *OSConfig, guessDefaultEditor func() string) (string, bool) {
|
func GetEditTemplate(osConfig *OSConfig, guessDefaultEditor func() string) (string, bool) {
|
||||||
preset := getPreset(osConfig, guessDefaultEditor)
|
preset := getPreset(osConfig, guessDefaultEditor)
|
||||||
template := osConfig.Edit
|
template := osConfig.Edit
|
||||||
@ -42,9 +44,11 @@ type editPreset struct {
|
|||||||
editAtLineTemplate string
|
editAtLineTemplate string
|
||||||
editAtLineAndWaitTemplate string
|
editAtLineAndWaitTemplate string
|
||||||
openDirInEditorTemplate string
|
openDirInEditorTemplate string
|
||||||
suspend bool
|
suspend func() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func returnBool(a bool) func() bool { return (func() bool { return a }) }
|
||||||
|
|
||||||
// IF YOU ADD A PRESET TO THIS FUNCTION YOU MUST UPDATE THE `Supported presets` SECTION OF docs/Config.md
|
// IF YOU ADD A PRESET TO THIS FUNCTION YOU MUST UPDATE THE `Supported presets` SECTION OF docs/Config.md
|
||||||
func getPreset(osConfig *OSConfig, guessDefaultEditor func() string) *editPreset {
|
func getPreset(osConfig *OSConfig, guessDefaultEditor func() string) *editPreset {
|
||||||
presets := map[string]*editPreset{
|
presets := map[string]*editPreset{
|
||||||
@ -52,12 +56,15 @@ func getPreset(osConfig *OSConfig, guessDefaultEditor func() string) *editPreset
|
|||||||
"vim": standardTerminalEditorPreset("vim"),
|
"vim": standardTerminalEditorPreset("vim"),
|
||||||
"nvim": standardTerminalEditorPreset("nvim"),
|
"nvim": standardTerminalEditorPreset("nvim"),
|
||||||
"nvim-remote": {
|
"nvim-remote": {
|
||||||
editTemplate: `nvim --server "$NVIM" --remote-tab {{filename}}`,
|
editTemplate: `[ -z "$NVIM" ] && (nvim -- {{filename}}) || (nvim --server "$NVIM" --remote-send "q" && nvim --server "$NVIM" --remote-tab {{filename}})`,
|
||||||
editAtLineTemplate: `nvim --server "$NVIM" --remote-tab {{filename}}; [ -z "$NVIM" ] || nvim --server "$NVIM" --remote-send ":{{line}}<CR>"`,
|
editAtLineTemplate: `[ -z "$NVIM" ] && (nvim +{{line}} -- {{filename}}) || (nvim --server "$NVIM" --remote-send "q" && nvim --server "$NVIM" --remote-tab {{filename}} && nvim --server "$NVIM" --remote-send ":{{line}}<CR>")`,
|
||||||
// No remote-wait support yet. See https://github.com/neovim/neovim/pull/17856
|
// No remote-wait support yet. See https://github.com/neovim/neovim/pull/17856
|
||||||
editAtLineAndWaitTemplate: `nvim +{{line}} {{filename}}`,
|
editAtLineAndWaitTemplate: `nvim +{{line}} {{filename}}`,
|
||||||
openDirInEditorTemplate: `nvim --server "$NVIM" --remote-tab {{dir}}`,
|
openDirInEditorTemplate: `[ -z "$NVIM" ] && (nvim -- {{dir}}) || (nvim --server "$NVIM" --remote-send "q" && nvim --server "$NVIM" --remote-tab {{dir}})`,
|
||||||
suspend: false,
|
suspend: func() bool {
|
||||||
|
_, ok := os.LookupEnv("NVIM")
|
||||||
|
return !ok
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"lvim": standardTerminalEditorPreset("lvim"),
|
"lvim": standardTerminalEditorPreset("lvim"),
|
||||||
"emacs": standardTerminalEditorPreset("emacs"),
|
"emacs": standardTerminalEditorPreset("emacs"),
|
||||||
@ -69,42 +76,42 @@ func getPreset(osConfig *OSConfig, guessDefaultEditor func() string) *editPreset
|
|||||||
editAtLineTemplate: "helix -- {{filename}}:{{line}}",
|
editAtLineTemplate: "helix -- {{filename}}:{{line}}",
|
||||||
editAtLineAndWaitTemplate: "helix -- {{filename}}:{{line}}",
|
editAtLineAndWaitTemplate: "helix -- {{filename}}:{{line}}",
|
||||||
openDirInEditorTemplate: "helix -- {{dir}}",
|
openDirInEditorTemplate: "helix -- {{dir}}",
|
||||||
suspend: true,
|
suspend: returnBool(true),
|
||||||
},
|
},
|
||||||
"helix (hx)": {
|
"helix (hx)": {
|
||||||
editTemplate: "hx -- {{filename}}",
|
editTemplate: "hx -- {{filename}}",
|
||||||
editAtLineTemplate: "hx -- {{filename}}:{{line}}",
|
editAtLineTemplate: "hx -- {{filename}}:{{line}}",
|
||||||
editAtLineAndWaitTemplate: "hx -- {{filename}}:{{line}}",
|
editAtLineAndWaitTemplate: "hx -- {{filename}}:{{line}}",
|
||||||
openDirInEditorTemplate: "hx -- {{dir}}",
|
openDirInEditorTemplate: "hx -- {{dir}}",
|
||||||
suspend: true,
|
suspend: returnBool(true),
|
||||||
},
|
},
|
||||||
"vscode": {
|
"vscode": {
|
||||||
editTemplate: "code --reuse-window -- {{filename}}",
|
editTemplate: "code --reuse-window -- {{filename}}",
|
||||||
editAtLineTemplate: "code --reuse-window --goto -- {{filename}}:{{line}}",
|
editAtLineTemplate: "code --reuse-window --goto -- {{filename}}:{{line}}",
|
||||||
editAtLineAndWaitTemplate: "code --reuse-window --goto --wait -- {{filename}}:{{line}}",
|
editAtLineAndWaitTemplate: "code --reuse-window --goto --wait -- {{filename}}:{{line}}",
|
||||||
openDirInEditorTemplate: "code -- {{dir}}",
|
openDirInEditorTemplate: "code -- {{dir}}",
|
||||||
suspend: false,
|
suspend: returnBool(false),
|
||||||
},
|
},
|
||||||
"sublime": {
|
"sublime": {
|
||||||
editTemplate: "subl -- {{filename}}",
|
editTemplate: "subl -- {{filename}}",
|
||||||
editAtLineTemplate: "subl -- {{filename}}:{{line}}",
|
editAtLineTemplate: "subl -- {{filename}}:{{line}}",
|
||||||
editAtLineAndWaitTemplate: "subl --wait -- {{filename}}:{{line}}",
|
editAtLineAndWaitTemplate: "subl --wait -- {{filename}}:{{line}}",
|
||||||
openDirInEditorTemplate: "subl -- {{dir}}",
|
openDirInEditorTemplate: "subl -- {{dir}}",
|
||||||
suspend: false,
|
suspend: returnBool(false),
|
||||||
},
|
},
|
||||||
"bbedit": {
|
"bbedit": {
|
||||||
editTemplate: "bbedit -- {{filename}}",
|
editTemplate: "bbedit -- {{filename}}",
|
||||||
editAtLineTemplate: "bbedit +{{line}} -- {{filename}}",
|
editAtLineTemplate: "bbedit +{{line}} -- {{filename}}",
|
||||||
editAtLineAndWaitTemplate: "bbedit +{{line}} --wait -- {{filename}}",
|
editAtLineAndWaitTemplate: "bbedit +{{line}} --wait -- {{filename}}",
|
||||||
openDirInEditorTemplate: "bbedit -- {{dir}}",
|
openDirInEditorTemplate: "bbedit -- {{dir}}",
|
||||||
suspend: false,
|
suspend: returnBool(false),
|
||||||
},
|
},
|
||||||
"xcode": {
|
"xcode": {
|
||||||
editTemplate: "xed -- {{filename}}",
|
editTemplate: "xed -- {{filename}}",
|
||||||
editAtLineTemplate: "xed --line {{line}} -- {{filename}}",
|
editAtLineTemplate: "xed --line {{line}} -- {{filename}}",
|
||||||
editAtLineAndWaitTemplate: "xed --line {{line}} --wait -- {{filename}}",
|
editAtLineAndWaitTemplate: "xed --line {{line}} --wait -- {{filename}}",
|
||||||
openDirInEditorTemplate: "xed -- {{dir}}",
|
openDirInEditorTemplate: "xed -- {{dir}}",
|
||||||
suspend: false,
|
suspend: returnBool(false),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,7 +148,7 @@ func standardTerminalEditorPreset(editor string) *editPreset {
|
|||||||
editAtLineTemplate: editor + " +{{line}} -- {{filename}}",
|
editAtLineTemplate: editor + " +{{line}} -- {{filename}}",
|
||||||
editAtLineAndWaitTemplate: editor + " +{{line}} -- {{filename}}",
|
editAtLineAndWaitTemplate: editor + " +{{line}} -- {{filename}}",
|
||||||
openDirInEditorTemplate: editor + " -- {{dir}}",
|
openDirInEditorTemplate: editor + " -- {{dir}}",
|
||||||
suspend: true,
|
suspend: returnBool(true),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,5 +156,5 @@ func getEditInTerminal(osConfig *OSConfig, preset *editPreset) bool {
|
|||||||
if osConfig.SuspendOnEdit != nil {
|
if osConfig.SuspendOnEdit != nil {
|
||||||
return *osConfig.SuspendOnEdit
|
return *osConfig.SuspendOnEdit
|
||||||
}
|
}
|
||||||
return preset.suspend
|
return preset.suspend()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user