Skip to content

Commit

Permalink
feat: add -s (silent) support for read builtin
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhulick committed Feb 29, 2024
1 parent 0763f7d commit b76e1c7
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion interp/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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":
Expand All @@ -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
}
Expand Down

0 comments on commit b76e1c7

Please sign in to comment.