diff options
| author | Junegunn Choi <junegunn.c@gmail.com> | 2021-03-25 19:56:18 +0900 |
|---|---|---|
| committer | Junegunn Choi <junegunn.c@gmail.com> | 2021-03-25 20:00:09 +0900 |
| commit | f84b3de24b63e2e26cbfa2a24e61a4173824fffd (patch) | |
| tree | 25628bb12f52c80c0b9cd4173b7512ce32139001 /src/tui/ttyname_unix.go | |
| parent | 6a1f3ec08b3bbe11d527cd9b32ac6275df11dbf9 (diff) | |
| download | fzf-f84b3de24b63e2e26cbfa2a24e61a4173824fffd.tar.gz | |
Automatically set /dev/tty as STDIN on execute action
https://github.com/junegunn/fzf/issues/1360#issuecomment-788178140
# Redirect /dev/tty to suppress "Vim: Warning: Input is not from a terminal"
ls | fzf --bind "enter:execute(vim {} < /dev/tty)"
# With this change, we can omit "< /dev/tty" part
ls | fzf --bind "enter:execute(vim {})"
Diffstat (limited to 'src/tui/ttyname_unix.go')
| -rw-r--r-- | src/tui/ttyname_unix.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/tui/ttyname_unix.go b/src/tui/ttyname_unix.go index 69bdfa54..68298cdc 100644 --- a/src/tui/ttyname_unix.go +++ b/src/tui/ttyname_unix.go @@ -4,6 +4,7 @@ package tui import ( "io/ioutil" + "os" "syscall" ) @@ -29,3 +30,18 @@ func ttyname() string { } return "" } + +// TtyIn returns terminal device to be used as STDIN, falls back to os.Stdin +func TtyIn() *os.File { + in, err := os.OpenFile(consoleDevice, syscall.O_RDONLY, 0) + if err != nil { + tty := ttyname() + if len(tty) > 0 { + if in, err := os.OpenFile(tty, syscall.O_RDONLY, 0); err == nil { + return in + } + } + return os.Stdin + } + return in +} |
