From 6465ce5146cfc6c0124abd114686697f8e73767d Mon Sep 17 00:00:00 2001 From: Matt Low Date: Sat, 4 Nov 2023 22:50:45 +0000 Subject: [PATCH] Trim placeholder from input via InputFromEditor --- pkg/cli/util.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/cli/util.go b/pkg/cli/util.go index 34b3de3..f9966d7 100644 --- a/pkg/cli/util.go +++ b/pkg/cli/util.go @@ -3,6 +3,7 @@ package cli import ( "os" "os/exec" + "strings" ) // InputFromEditor retrieves user input by opening an editor (one specified by @@ -34,8 +35,15 @@ func InputFromEditor(placeholder string, pattern string) (string, error) { bytes, _ := os.ReadFile(msgFile.Name()) content := string(bytes) - if content == placeholder { - return "", nil + if placeholder != "" { + if content == placeholder { + return "", nil + } + + // strip placeholder if content begins with it + if strings.HasPrefix(content, placeholder) { + content = content[len(placeholder):] + } } return content, nil