From 1ce6c29e6ab7061c9e914beb6d17884cdd1862a8 Mon Sep 17 00:00:00 2001 From: Chris Lane Date: Sun, 2 Feb 2020 15:48:45 -0500 Subject: [PATCH] fix: issue #301 Attempts to resolve issue #301, whereby `cheat` fails if `$EDITOR` (or equivalent) contains flags. --- cmd/cheat/cmd_edit.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cmd/cheat/cmd_edit.go b/cmd/cheat/cmd_edit.go index 6d895fa..7ab2b0e 100644 --- a/cmd/cheat/cmd_edit.go +++ b/cmd/cheat/cmd_edit.go @@ -99,8 +99,15 @@ func cmdEdit(opts map[string]interface{}, conf config.Config) { } } + // split `conf.Editor` into parts to separate the editor's executable from + // any arguments it may have been passed. If this is not done, the nearby + // call to `exec.Command` will fail. + parts := strings.Fields(conf.Editor) + editor := parts[0] + args := append(parts[1:], editpath) + // edit the cheatsheet - cmd := exec.Command(conf.Editor, editpath) + cmd := exec.Command(editor, args...) cmd.Stdout = os.Stdout cmd.Stdin = os.Stdin cmd.Stderr = os.Stderr