From 1a50535f45ce045f39886103fb9b74eb13a884be Mon Sep 17 00:00:00 2001 From: raj Date: Sun, 22 Oct 2023 15:59:12 +0530 Subject: [PATCH] fix: default to nvim if available --- project-manager/main.go | 9 +++++++-- utils/editor.go | 12 +++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/project-manager/main.go b/project-manager/main.go index d283947..afb757d 100644 --- a/project-manager/main.go +++ b/project-manager/main.go @@ -46,7 +46,7 @@ var ListProjects = &cobra.Command{ // print a vim command to open the config file editorCommand, err := projectconfig.GetEditorCommand(selectedRow[0]) if err != nil { - editorCommand = "vim" + editorCommand = "" } utils.EditFile(projectconfig.ProjectConfigFilePath(selectedRow[0]), editorCommand) log.Debug("Opened config file", "file", projectconfig.ProjectConfigFilePath(selectedRow[0])) @@ -150,7 +150,12 @@ var InitCmd = &cobra.Command{ if err != nil { logger.Error(err) } else { - fmt.Println("Created Project, set up your config by editing:", ppath) + editorCommand, err := projectconfig.GetEditorCommand(projectName) + if err != nil { + editorCommand = "" + } + utils.EditFile(ppath, editorCommand) + fmt.Println("Created Project, config is at:", ppath) } }, } diff --git a/utils/editor.go b/utils/editor.go index dbb9351..c9066a0 100644 --- a/utils/editor.go +++ b/utils/editor.go @@ -5,9 +5,19 @@ import ( "os/exec" ) +func checkNvimExists() bool { + cmd := exec.Command("nvim", "--version") + err := cmd.Run() + return err == nil +} + func EditFile(filePath string, editorCommand string) error { if editorCommand == "" { - editorCommand = "vim" + if checkNvimExists() { + editorCommand = "nvim" + } else { + editorCommand = "vim" + } } cmd := exec.Command(editorCommand, filePath)