commit afbbd5fb52b2922c803eeb95aa91a85c98944420
parent 775a262de21a8c381f4535ea697739450422223d
Author: Sean Enck <sean@ttypty.com>
Date: Wed, 6 Oct 2021 18:42:23 -0400
detect pipe for socket credential management
Diffstat:
3 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/cmd/lb/main.go b/cmd/lb/main.go
@@ -75,7 +75,7 @@ func main() {
default:
stock.Die("too many arguments", internal.NewLockboxError("insert can only perform one operation"))
}
- isPipe := isInputFromPipe()
+ isPipe := internal.IsInputFromPipe()
entry := getEntry(store, args, idx)
if stock.PathExists(entry) {
if !isPipe {
@@ -213,8 +213,3 @@ func confirm(prompt string) bool {
}
return resp == "Y" || resp == "y"
}
-
-func isInputFromPipe() bool {
- fileInfo, _ := os.Stdin.Stat()
- return fileInfo.Mode()&os.ModeCharDevice == 0
-}
diff --git a/internal/socket.go b/internal/socket.go
@@ -154,9 +154,14 @@ func SocketHandler(isHost bool) error {
return err
}
if data == respCommand {
- termEcho(false)
+ isPipe := IsInputFromPipe()
+ if !isPipe {
+ termEcho(false)
+ }
input, err := Stdin(true)
- termEcho(true)
+ if !isPipe {
+ termEcho(true)
+ }
if err != nil {
return err
}
diff --git a/internal/utils.go b/internal/utils.go
@@ -132,3 +132,9 @@ func Stdin(one bool) (string, error) {
}
return strings.TrimSpace(string(b)), nil
}
+
+// IsInputFromPipe will indicate if connected to stdin pipe.
+func IsInputFromPipe() bool {
+ fileInfo, _ := os.Stdin.Stat()
+ return fileInfo.Mode()&os.ModeCharDevice == 0
+}