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)