repo: fallback editor list by looking if the binary exist

Michael Muré created

Change summary

repository/gogit.go | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)

Detailed changes

repository/gogit.go 🔗

@@ -5,6 +5,7 @@ import (
 	"fmt"
 	"io/ioutil"
 	"os"
+	"os/exec"
 	stdpath "path"
 	"path/filepath"
 	"strings"
@@ -231,7 +232,22 @@ func (repo *GoGitRepo) GetCoreEditor() (string, error) {
 		return val, nil
 	}
 
-	return "vi", nil
+	priorities := []string{
+		"editor",
+		"nano",
+		"vim",
+		"vi",
+		"emacs",
+	}
+
+	for _, cmd := range priorities {
+		if _, err = exec.LookPath(cmd); err == nil {
+			return cmd, nil
+		}
+
+	}
+
+	return "ed", nil
 }
 
 // GetRemotes returns the configured remotes repositories.