mirror of https://github.com/xrehpicx/pee.git
fix: default to nvim if available
This commit is contained in:
parent
221b199a1d
commit
1a50535f45
|
@ -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)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue