[PATCH] Respect $EDITOR and $VISUAL
Export this patch
diff --git a/hcwiki.go b/hcwiki.go
index a305f2e..a09c2eb 100644
--- a/hcwiki.go
+++ b/hcwiki.go
@@ -160,6 +160,19 @@ func buildFiles(conf config) map[string]interface{} {
return builtTags
}
+func getEditor() string {
+ // Get the user's preffered editor
+ // or, fall back to:
+ // $VISUAL, $EDITOR, nano
+ if visual := os.Getenv("VISUAL"); visual != "" {
+ return visual;
+ }
+ if editor := os.Getenv("EDITOR"); editor != "" {
+ return editor;
+ }
+ return "nano"
+}
+
func main() {
// use the toml parser to read in the config, based on the Config struct
var conf config
@@ -212,11 +225,11 @@ Usage:
} else if arguments["edit"] == true {
if path.Ext(arguments["<page>"].(string)) == ".gmi" {
- cmd := exec.Command("nano", conf.PathToSource+"/"+arguments["<page>"].(string))
+ cmd := exec.Command(getEditor(), conf.PathToSource+"/"+arguments["<page>"].(string))
runCMD(cmd)
} else {
- cmd := exec.Command("nano", conf.PathToSource+"/"+arguments["<page>"].(string)+".gmi")
+ cmd := exec.Command(getEditor(), conf.PathToSource+"/"+arguments["<page>"].(string)+".gmi")
runCMD(cmd)
}
--
2.33.0