-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Executing fg via binding makes keybindings not work the second time #2114
Comments
I can reproduce this. Some more info:
In other words:
|
HAhAHAHAhA.... that was my attempt at a reference... 😆 |
Hehe, yes, I got that 😉 |
This is really unfortunate, as I run into this multiple times a day. |
@jonhoo: It's possible fish isn't resetting the terminal mode correctly. For me with a ToT fish just executing a single command (like |
Simply pressing enter after suspending the command the second time fixes the fish input state. I'm confident this is not a tty mode problem. You don't even need to use a full-screen program like vim or less. Simply running Frankly, I'm not sure this should even be allowed. If you've already started typing another command then press \cR to magically foreground a job what do you expect to happen to the characters you've already entered? If we do want to support this the fix probably lies in having the code that responds to \cZ (or whatever the suspend key is) forcibly redraw the command line and otherwise ensure it is in a sane state. @jonhoo, I'm curious why you created that binding? Why not just type |
@krader1961: I don't think there's something magical about \cR with regards to output. The same could be said for \cZ and then manually typing |
@jonhoo: You misunderstood me. I agree there is nothing magical about the specific key sequence you bind the |
@krader1961: Oh, sorry. Yes, I'd be fine with this being disallowed if you were in the middle of typing a command. However, it should work fine if you haven't yet typed anything. While you're right it doesn't save much time, it certainly interrupts the flow somewhat if I'm flicking back and forth between, say, vim and my terminal, typing in something based on the command I just ran. I could use multiple terminal tabs/windows, but anything involving tab is fairly slow, as it's far from home row. |
I believe it should work if something is already typed in if at all possible. Imagine if you're looking at a man page or another reference and wish to switch to/from the manual; it could be very useful. In addition, fg could be only part of a larger binding. It is certainly annoying and prone to error to type the binding and thent typing in fg and enter. It's yet more characters if you wish to, say, run a command after fg separated by a semicolon, or type a space before fg to not log the command. In addition, it clutters up the terminal after exiting from the command. I am trying to do all of these things, as anyone trying to make fg part of a larger command might need to do. |
@rbong, I'm afraid I don't understand any of the scenarios you describe. Let's start with the first one:
If I've typed If the latter wouldn't it be simpler to simply open another shell and run the man command in parallel? That's what I normally do. That is, I normally have one or two terminals that I use for looking at documentation or source code while I'm actually editing code or entering other commands in a different window. That's more simpler and more general than what you seem to be trying to do.
Huh? Under what circumstances does it make sense to put a process in the background then type something like
Double huh? Entering a space before fg will only keep fg from being logged. It will have absolutely no effect on whether the command being foregrounded was logged. |
Sorry for my confusing scenarios @krader1961
It is the latter scenario. I admittedly also open another window... however, I can see how someone would find this useful. On systems with smaller screens restricted to the terminal, the user is forced to use a multiplexer, as I have been many times. With this scenario, I meant to illustrate that it is in fact useful to have just fg in a keybinding and to use that keybinding in the middle of writing a command.
In this scenario where the user is going from and to some foreground process (a very good reason for binding fg to a keystroke), the user may need to clutter up the window with fg commands. A user will eventually run
Or,
Or, wrap clear and fg in a function. It's probably not a good idea to name a function only one or two letters, meaning it's still more than a few extra keystrokes.
This is what I mean. fg will not be logged. If the user desires fg to be in a keybinding along with some other functionality, they probably wish to hide the command. I am just illustrating that it's more than just one extra keystroke because of the extra shell management required to recieve the same result. |
Entering [space]fg might make sense in shells which log each command. But, FWIW, it's not a useful optimization in fish because fish will only ever have one instance of each unique fg command in the history file. I've been programming since the days when 80 column IBM/Hollerith cards were still being used and a 80x24 CRT terminal was bleeding edge. Having two such terminals was considered a luxury. And yet I can't ever recall typing |
@krader1961 It's not a big deal, just a slight nuisance. If my scenarios seem weird, it's because I am using remote key presses in tmux to suspend any foreground processes, do something, and then go back without worrying about what just happened. It's two keypresses if fg works in a keybinding, which is fast uninterruptable and clean, but otherwise I have to worry about the state of various other things in the shell like I mentioned. I think I failed to generalize my situation. |
This problem is caused by commit b67526a, which disabled the code that would otherwise restore the correct terminal mode after returning from a job. Reverting that change allows *Edit: the original bug reappears if the change is rolled back. I don't know exactly how to make everything work, but it definitely has to do with the block of code in b67526a. A reliable test case for me is |
I believe this patch fixes the issue without reintroducing the original bug #121: 1035c1035
< static bool terminal_return_from_job(job_t *j) {
---
> static bool terminal_return_from_job(job_t *j, int restore_attrs) {
1060,1072c1060,1070
< // Disabling this per
< // https://github.com/adityagodbole/fish-shell/commit/9d229cd18c3e5c25a8bd37e9ddd3b67ddc2d1b72 On
< // Linux, 'cd . ; ftp' prevents you from typing into the ftp prompt. See
< // https://github.com/fish-shell/fish-shell/issues/121
< #if 0
< // Restore the shell's terminal modes.
< if (tcsetattr(STDIN_FILENO, TCSADRAIN, &shell_modes) == -1) {
< if (errno == EIO) redirect_tty_output();
< debug(1, _(L"Could not return shell to foreground"));
< wperror(L"tcsetattr");
< return false;
< }
< #endif
---
> // Need to restore the terminal's attributes or `bind \cF fg` will put the
> // terminal into a broken state (until "enter" is pressed).
> // See: https://github.com/fish-shell/fish-shell/issues/2114
> if (restore_attrs) {
> if (tcsetattr(STDIN_FILENO, TCSADRAIN, &shell_modes) == -1) {
> if (errno == EIO) redirect_tty_output();
> debug(1, _(L"Could not return shell to foreground"));
> wperror(L"tcsetattr");
> return false;
> }
> }
1091c1089,1092
< terminal_return_from_job(this);
---
> // Only restore terminal attrs if we're continuing a job. See:
> // https://github.com/fish-shell/fish-shell/issues/121
> // https://github.com/fish-shell/fish-shell/issues/2114
> terminal_return_from_job(this, send_sigcont); |
@ridiculousfish @faho @mqudsi would you be able to take a look at the comments and patch from @bruce-hill and see if this is something we should take for 3.1? |
Tentatively pulling into 3.1 so we don't lose it. |
This fix looks good and makes sense, fixed as 9fd9f70 . Thanks @bruce-hill ! |
Prior to this change, when a process resumes because it is brought back to the foreground, we would reset the terminal attributes to shell mode. This fixed fish-shell#2114 but subtly introduced fish-shell#7483. This backs out 9fd9f70, re-introducing fish-shell#2114 and re-fixing fish-shell#7483. A followup fix will re-fix fish-shell#2114; these are broken out separately for bisecting purposes. Fixes fish-shell#7483.
Prior to this change, when a process resumes because it is brought back to the foreground, we would reset the terminal attributes to shell mode. This fixed fish-shell#2114 but subtly introduced fish-shell#7483. This backs out 9fd9f70, re-introducing fish-shell#2114 and re-fixing fish-shell#7483. A followup fix will re-fix fish-shell#2114; these are broken out separately for bisecting purposes. Fixes fish-shell#7483.
Prior to this change, when a process resumes because it is brought back to the foreground, we would reset the terminal attributes to shell mode. This fixed fish-shell#2114 but subtly introduced fish-shell#7483. This backs out 9fd9f70, re-introducing fish-shell#2114 and re-fixing fish-shell#7483. A followup fix will re-fix fish-shell#2114; these are broken out separately for bisecting purposes. Fixes fish-shell#7483.
Prior to this change, when a process resumes because it is brought back to the foreground, we would reset the terminal attributes to shell mode. This fixed fish-shell#2114 but subtly introduced fish-shell#7483. This backs out 9fd9f70, re-introducing fish-shell#2114 and re-fixing fish-shell#7483. A followup fix will re-fix fish-shell#2114; these are broken out separately for bisecting purposes. Fixes fish-shell#7483.
Prior to this fix, when key binding is a script command (i.e. not a readline command), fish would run that key binding using fish's shell tty modes. Switch to using the external tty modes. This re-fixes issue #2214.
Reopening because the fix for #7770 reintroduces this |
Restore terminal modes after running key bindings with external commands This concerns the behavior when running an external command from a key binding. The history is: Prior to 5f16a29, fish would run these external commands in shell modes. This meant that fish would pick up any tty changes from external commands (see fish-shell#2114). After 5f16a29, fish would save and restore its shell modes around these external commands. This introduced a regression where anything the user typed while a bound external command was executing would be echoed, because external command mode has ECHO set in c_lflag. (This can be reproed easily with `bind -q 'sleep 1'` and then pressing q and typing). So 5f16a29 was reverted in fd93559. This commit partially reverts fd93559. It has it both ways: external commands are launched with shell modes, and also shell modes are restored after the external command completes. This supports commands which muck with the tty, but does not trigger ECHO mode. Fixes fish-shell#7770. Fixes fish-shell#2114 (for the third time!) This partially reverts commit fd93559.
With this binding in
config.fish
:Do the following commands in a new shell:
In particular, no key bindings work at this point until enter or
^J
is pressed.The text was updated successfully, but these errors were encountered: