You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
external commands launched from config.fish don't have the correct tty modes #2980
When I run /bin/rm -i in fish 2.3b1 in Cygwin, the command waits for me to answer y or n, but it doesn't receive any keyboard input. I have to press Ctrl-C to abort the command.
Reproduction Steps:
Run touch tstfile
Run /bin/rm -i tstfile
Command responds with /bin/rm: remove regular empty file 'tstfile'?
Expected behavior:
Command accepts y or n as an answer.
Observed behavior:
No keyboard input is accepted. The command hangs until I interrupt it with Ctrl-C.
Additional information:
rm -i worked fine in fish 2.2.0 in Cygwin.
fish-2.3b1-1 is available in Cygwin setup as a test release (or it will be shortly) (click on "Exp" at the top right to see test releases).
What happens if you press "y" or "n" followed by [ctrl-J] rather than [enter]? Do any other commands that read from stdin ignore their input? For example, what happens if you run cat and enter a line of text followed by [ctrl-D]?
It suggests the tty modes (e.g., what stty -a shows) aren't being set correctly. Normally icrnl mode is enabled on the tty to map \cM (carriage-return, what [enter] sends) to \cJ (newline). If icrnl mode is disabled you get the behavior you're observing. What isn't clear is why it is affecting just the /bin/rm -i prompt given that tty input to other commands is being correctly handled. I wonder if /bin/rm is opening /dev/tty to issue that prompt and read the response. That shouldn't make any difference but it's the only thing I can think of which might be relevant.
Please run stty -a so we can confirm the tty modes are set in a sane fashion for external commands.
The -icrnl is the problem. I'm betting it's not affecting the cat and sort commands because they're reading from stdin in "text" mode and the Cygwin shims are mapping the carriage-return to newline. Whereas rm -i is probably opening /dev/tty in binary mode thus causing Cygwin to not do that mapping.
So now the question is why the tty modes aren't being reset to sane values by fish when it spawns an external command. I don't currently have Cygwin environment setup so I can't investigate this. For anyone who can build a debug version to run on Cygwin I would start by instrumenting restore_term_mode() to report whether the tcsetattr() call it does is failing and what the errno is.
P.S., The fact that we don't report unexpected syscall failures is itself a problem. We should at least be doing so if the debug level is greater than one.
It certainly suggests that there's something in screen that doesn't cooperate with the modes that fish expects, but I'm not sure why. Do you have anything in your .screenrc?
changed the title [-]rm -i doesn't accept input in fish 2.3b1 in Cygwin[/-][+]rm -i doesn't accept input in fish 2.3b1 within screen in Cygwin[/+]on Apr 29, 2016
The "y" that I typed at the prompt wasn't echoed, and pressing the Enter key didn't work - I had to type Ctrl-J.
This was in a shell within screen, when screen was started from ~/.config/fish/config.fish. If I wait instead for the initial fish prompt and then manually launch screen, this problem doesn't occur.
This is still unresolved. Which is why the issue is still open 😄
At the present time the only way to run an external command from your ~/.config/fish/config.fish if it depends on the tty modes is to prefix it with exec. Doing so means, obviously, that command will be the last command in your config that is run.
I can unfortunately also reproduce this issue, rm -i indead fails to work if in config.fish.
I checked the output of stty -a, and here are the differences I noticed:
when run in config.fish: -icrnl -icanon -iexten -echo
when run after config.fish (once I have a normal interactive prompt) icrnl icanon iexten echo
Manually adding stty icrnl icanon iexten echo to the top of my fish.config file solved the problem!
Information about the system I was running this on:
~> fish --version
fish, version 2.7.1-934-g9a5afe3
~> uname -a
Linux fisher 4.4.0-116-generic #140-Ubuntu SMP Mon Feb 12 21:23:04 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
~> echo $TERM
xterm-256color
~> echo -e '\x05'
~> PuTTY
Okay, I'm pushing a fix for this, which just removes a hack put in in #2578. It's not perfect - in particular it'll cause issues if someone has a slow config.fish and uses something like tmuxinator with a binding for ctrl-j, but I believe that to be a much rarer usecase than "something that prompts in config.fish". Also it's easier to work around (add a "sleep").
Activity
krader1961 commentedon Apr 27, 2016
What happens if you press "y" or "n" followed by [ctrl-J] rather than [enter]? Do any other commands that read from stdin ignore their input? For example, what happens if you run
catand enter a line of text followed by [ctrl-D]?andrew-schulman commentedon Apr 28, 2016
Fascinating. Yes, if I do that the rm command removes the file and returns, all without echoing any input:
Dunno what that means, but I guess you do.
cat works normally:
So does sort:
krader1961 commentedon Apr 28, 2016
It suggests the tty modes (e.g., what
stty -ashows) aren't being set correctly. Normally icrnl mode is enabled on the tty to map \cM (carriage-return, what [enter] sends) to \cJ (newline). If icrnl mode is disabled you get the behavior you're observing. What isn't clear is why it is affecting just the/bin/rm -iprompt given that tty input to other commands is being correctly handled. I wonder if /bin/rm is opening /dev/tty to issue that prompt and read the response. That shouldn't make any difference but it's the only thing I can think of which might be relevant.Please run
stty -aso we can confirm the tty modes are set in a sane fashion for external commands.andrew-schulman commentedon Apr 28, 2016
krader1961 commentedon Apr 28, 2016
The
-icrnlis the problem. I'm betting it's not affecting thecatandsortcommands because they're reading from stdin in "text" mode and the Cygwin shims are mapping the carriage-return to newline. Whereasrm -iis probably opening /dev/tty in binary mode thus causing Cygwin to not do that mapping.So now the question is why the tty modes aren't being reset to sane values by fish when it spawns an external command. I don't currently have Cygwin environment setup so I can't investigate this. For anyone who can build a debug version to run on Cygwin I would start by instrumenting
restore_term_mode()to report whether thetcsetattr()call it does is failing and what the errno is.P.S., The fact that we don't report unexpected syscall failures is itself a problem. We should at least be doing so if the debug level is greater than one.
zanchey commentedon Apr 28, 2016
Did this work in 2.2.0?
andrew-schulman commentedon Apr 28, 2016
Yes, it works as expected in fish 2.2.0 in Cygwin.
zanchey commentedon Apr 28, 2016
Annoyingly, I can't reproduce this - either with the current source, or with the 2.3b1 build from Cygwin.
How are you starting fish within mintty?
andrew-schulman commentedon Apr 28, 2016
OK. In fact, I run fish within screen, in mintty. I didn't check it before, but the input to
rm -iworks fine in mintty without screen:But it has the problem inside screen:
Sorry for not checking that before.
So is that screen's fault?
zanchey commentedon Apr 29, 2016
It certainly suggests that there's something in screen that doesn't cooperate with the modes that fish expects, but I'm not sure why. Do you have anything in your
.screenrc?andrew-schulman commentedon Apr 29, 2016
In Cygwin, /etc/screenrc has:
And my personal ~/.screenrc has:
[-]rm -i doesn't accept input in fish 2.3b1 in Cygwin[/-][+]rm -i doesn't accept input in fish 2.3b1 within screen in Cygwin[/+]13 remaining items
andrew-schulman commentedon Oct 31, 2016
I thought this was fixed in 2.3.1, but now I find that it's not. To reiterate:
The "y" that I typed at the prompt wasn't echoed, and pressing the Enter key didn't work - I had to type Ctrl-J.
This was in a shell within screen, when screen was started from ~/.config/fish/config.fish. If I wait instead for the initial fish prompt and then manually launch screen, this problem doesn't occur.
The problem is still there in 2.4b1.
krader1961 commentedon Oct 31, 2016
This is still unresolved. Which is why the issue is still open 😄
At the present time the only way to run an external command from your ~/.config/fish/config.fish if it depends on the tty modes is to prefix it with
exec. Doing so means, obviously, that command will be the last command in your config that is run.Ambrevar commentedon Apr 28, 2017
I cannot reproduce anymore, this seems to be fixed on the master branch.
andrew-schulman commentedon Apr 28, 2017
Still broken for me in current Cygwin x86_64, with fish built from the latest HEAD (a26419).
IsaacOscar commentedon Mar 11, 2018
I can unfortunately also reproduce this issue,
rm -iindead fails to work if in config.fish.I checked the output of
stty -a, and here are the differences I noticed:-icrnl -icanon -iexten -echoicrnl icanon iexten echoManually adding
stty icrnl icanon iexten echoto the top of my fish.config file solved the problem!Information about the system I was running this on:
andrew-schulman commentedon Mar 31, 2019
This is unfortunately not fixed in fish 3.0.2 in Cygwin.
faho commentedon Apr 5, 2019
Okay, I'm pushing a fix for this, which just removes a hack put in in #2578. It's not perfect - in particular it'll cause issues if someone has a slow config.fish and uses something like tmuxinator with a binding for ctrl-j, but I believe that to be a much rarer usecase than "something that prompts in config.fish". Also it's easier to work around (add a "sleep").
andrew-schulman commentedon Apr 5, 2019
Confirmed fixed. Thanks!