Trim placeholder from input via InputFromEditor

This commit is contained in:
Matt Low 2023-11-04 22:50:45 +00:00
parent ca45159ec3
commit 6465ce5146
1 changed files with 10 additions and 2 deletions

View File

@ -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