~arcade/hcwiki-devel

Respect $EDITOR and $VISUAL v2 APPLIED

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/25257/mbox | git am -3
Learn more about email & git

[PATCH v2] Respect $EDITOR and $VISUAL Export this patch

diff --git a/hcwiki.go b/hcwiki.go
index ff6bc3f..a4ab5a8 100644
--- a/hcwiki.go
+++ b/hcwiki.go
@@ -162,6 +162,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
@@ -214,11 +227,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