Skip to content
Myr

Automatically set /dev/tty as STDIN on execute action

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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 {})"

authored by Junegunn Choi · committed by Junegunn Choi · parent 6a1f3ec · Browse files · 3 files+24 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+24 added−1 removed

  • other:+24 added−1 removed

3 files+24 added−1 removed

modified:src/tui/ttyname_unix.go+16 added
2 unmodified lines
3package tui45import (6 "io/ioutil"7 "os"8 "syscall"9)1011var devPrefixes = [...]string{"/dev/pts/", "/dev/"}
17 unmodified lines
29 }30 }31 return ""32}3334// TtyIn returns terminal device to be used as STDIN, falls back to os.Stdin35func TtyIn() *os.File {36 in, err := os.OpenFile(consoleDevice, syscall.O_RDONLY, 0)37 if err != nil {38 tty := ttyname()39 if len(tty) > 0 {40 if in, err := os.OpenFile(tty, syscall.O_RDONLY, 0); err == nil {41 return in42 }43 }44 return os.Stdin45 }46 return in47}
modified:src/tui/ttyname_windows.go+7 added
1// +build windows23package tui45import "os"67func ttyname() string {8 return ""9}1011// TtyIn on Windows returns os.Stdin12func TtyIn() *os.File {13 return os.Stdin14}
modified:src/terminal.go+1 added-1 removed
1721 unmodified lines
1722 }1723 command := t.replacePlaceholder(template, forcePlus, string(t.input), list)1724 cmd := util.ExecCommand(command, false)1725 if !background {1726 cmd.Stdin = os.Stdin1726 cmd.Stdin = tui.TtyIn()1727 cmd.Stdout = os.Stdout1728 cmd.Stderr = os.Stderr1729 t.tui.Pause(true)1730 t.executing.Set(true)
1013 unmodified lines