From b76e1c7307c6ecd10479b8fd76514c3ec5974abe Mon Sep 17 00:00:00 2001 From: David Hulick Date: Wed, 28 Feb 2024 15:10:35 -0500 Subject: [PATCH] feat: add -s (silent) support for read builtin --- interp/builtin.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/interp/builtin.go b/interp/builtin.go index b24a3d6a..42c07c1d 100644 --- a/interp/builtin.go +++ b/interp/builtin.go @@ -14,9 +14,11 @@ import ( "path/filepath" "strconv" "strings" + "syscall" "mvdan.cc/sh/v3/expand" "mvdan.cc/sh/v3/syntax" + "golang.org/x/term" ) func isBuiltin(name string) bool { @@ -559,10 +561,15 @@ func (r *Runner) builtinCode(ctx context.Context, pos syntax.Pos, name string, a r.setErr(returnStatus(code)) case "read": var prompt string + var line []byte + var err error raw := false + silent := false fp := flagParser{remaining: args} for fp.more() { switch flag := fp.flag(); flag { + case "-s": + silent = true case "-r": raw = true case "-p": @@ -589,7 +596,12 @@ func (r *Runner) builtinCode(ctx context.Context, pos syntax.Pos, name string, a r.out(prompt) } - line, err := r.readLine(raw) + if silent { + line, err = term.ReadPassword(int(syscall.Stdin)) + }else{ + line, err = r.readLine(raw) + } + if err != nil { return 1 }