From 4e305eca26924a14d05758fb381edca1c5a5f55b Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Tue, 14 Feb 2023 23:21:34 +0900 Subject: [PATCH] become: Set stdin to /dev/tty --- src/terminal.go | 1 + src/util/util_unix.go | 6 ++++++ src/util/util_windows.go | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/src/terminal.go b/src/terminal.go index 18f8353..8ab5434 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -2876,6 +2876,7 @@ func (t *Terminal) Loop() { if t.history != nil { t.history.append(string(t.input)) } + util.SetStdin(tui.TtyIn()) syscall.Exec(shellPath, []string{shell, "-c", command}, os.Environ()) } } diff --git a/src/util/util_unix.go b/src/util/util_unix.go index a76f770..2991fd2 100644 --- a/src/util/util_unix.go +++ b/src/util/util_unix.go @@ -6,6 +6,8 @@ import ( "os" "os/exec" "syscall" + + "golang.org/x/sys/unix" ) // ExecCommand executes the given command with $SHELL @@ -45,3 +47,7 @@ func SetNonblock(file *os.File, nonblock bool) { func Read(fd int, b []byte) (int, error) { return syscall.Read(int(fd), b) } + +func SetStdin(file *os.File) { + unix.Dup2(int(file.Fd()), 0) +} diff --git a/src/util/util_windows.go b/src/util/util_windows.go index b3f4e01..aa69b99 100644 --- a/src/util/util_windows.go +++ b/src/util/util_windows.go @@ -81,3 +81,7 @@ func SetNonblock(file *os.File, nonblock bool) { func Read(fd int, b []byte) (int, error) { return syscall.Read(syscall.Handle(fd), b) } + +func SetStdin(file *os.File) { + // No-op +}