~arcade/hcwiki-devel

Respect $EDITOR and $VISUAL v1 REJECTED

Scott Little: 1
 Respect $EDITOR and $VISUAL

 1 files changed, 15 insertions(+), 2 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~arcade/hcwiki-devel/patches/25256/mbox | git am -3
Learn more about email & git

[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