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 93c7a79
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,7 +14,9 @@ import (
"path/filepath"
"strconv"
"strings"
"syscall"

"golang.org/x/term"
"mvdan.cc/sh/v3/expand"
"mvdan.cc/sh/v3/syntax"
)
Expand Down Expand Up @@ -560,9 +562,12 @@ func (r *Runner) builtinCode(ctx context.Context, pos syntax.Pos, name string, a
case "read":
var prompt string
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 +594,14 @@ func (r *Runner) builtinCode(ctx context.Context, pos syntax.Pos, name string, a
r.out(prompt)
}

line, err := r.readLine(raw)
var line []byte
var err error
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 93c7a79

Please sign in to comment.