elves / elvish

Powerful scripting language & versatile interactive shell
https://elv.sh/
BSD 2-Clause "Simplified" License
5.67k stars 299 forks source link

Do not launch the line editor when reading from standard input #661

Open notramo opened 6 years ago

notramo commented 6 years ago

I think it shouldn't launch the editor in this case.

echo "echo 'string'" | elvish

If stdin is not a tty, bash, sh, and zsh reads the script from it:

echo "echo 'string'" | zsh
xiaq commented 6 years ago

That's the way it should work; considering this a bug.

krader1961 commented 4 years ago

FWIW, This is really about how elvish determines whether it is interactive. This unexpected behavior is still present:

$ echo "echo 'string'" | elvish
compilation error: variable $edit:completion:matcher not found
/Users/krader/.elvish/rc.elv, line 118: edit:completion:matcher[''] = [p]{ edit:match-prefix &smart-
case $p }
/Users/krader> string
/Users/krader> ⏎
krader1961 commented 4 years ago

FYI, I have a fix for this. However, all of the tests in pkg/shell/interact_test.go depend on the existing, unwanted, behavior. Those tests need to be changed to use a PTY. Sadly, Go doesn't have any native support for PTYs. Presumably because they are not portable and a niche feature for a language like Go. So the question is whether we want to depend on a Go package like https://github.com/creack/pty or instead rewrite interactive tests to use the expect utility.

krader1961 commented 4 years ago

I see that one unit test, pkg/cli/term/setup_unix_test.go, already depends github.com/kr/pty which is the predecessor of github.com/creack/pty. Since the former package is no longer being maintained switch that use to the latter package. Also, use the latter package in the tests of interactive behavior. That will, unfortunately, mean the interactive tests won't run on Windows.