-
-
Notifications
You must be signed in to change notification settings - Fork 84
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
ble.sh thinks coproc are jobs on C-d, native bash does not #302
Comments
I think it is technically possible to mimic Bash's behavior so that C-d skips the check for coproc jobs. I'd consider it later.
As far as I know, Bash doesn't clean up coproc processes on the session exit, though the coproc processes might receive errors in reading stdin or outputting to stdout. |
As I have replied in the help-bash mailing list, there are already some codes in |
I now tried to check the detailed behavior of Bash, but Bash doesn't seem to change the behavior of C-d for normal background jobs and coproc jobs. When the coproc process is suspended, Bash doesn't exit with C-d: $ LANG=C bash --norc
$ coproc a { sleep 100; }
[1] 1620290
$ fg
coproc a { sleep 100; }
<C-z>^Z
[1]+ Stopped coproc a { sleep 100; }
$<C-d>
exit
There are stopped jobs.
$ I think the behavior difference that you noticed is not the difference between the normal background jobs and coproc jobs. I think it is the difference between running background jobs and suspended background jobs. While Bash only checks for suspended background jobs, ble.sh intentionally checks both types of jobs before attempting to exit the session with C-d. If Bash exits without properly finishing the running jobs, those jobs will continue to run after the session is ended. This is also the case for coproc processes, though in some cases the coproc processes might fail with pipe errors or other types of crashes. On the other hand, as C-d is also used to delete the character on the current position, one could mistakenly hit C-d on an empty command line, and the Bash can exit unintendedly. I think this is a problem, so ble.sh intentionally blocks the exiting by C-d when there are any types of background jobs. |
You're right about background vs suspended and therefore again ble.sh behavior looks better even before the C-d consideration. There's also disown command that I didn't know about to hide from 'jobs' etc. These coproc don't survive past termination of parent process I expect due to default SIGPIPE dispensation, which seems like enough given that purpose of coproc seems to be convenient setup of piped child. So it looks like the only remaining question is about the status of coproc implementation with respect to multiple coproc. The mailing list response on this contradicts some info elsewhere on this and I'm going to see what's going on with recent bash build options. |
This is a reply to the blesh-related comments in the
Yes. If you would like to output anything to stderr, such commands should be put before ble-attach. This is the reason that the above line needs to be put at the bottom of ~/bashrc.
Some of the options are dynamically defined by modules, which might not be yet defined by the module. The recommended way is to use the proper hooks (
Yes, that is actually the proper way. If you could give me the list of the option names that you do not know which hooks to put them in, I can tell you the corresponding hook names. Or you might just grep But if you would like to forcibly define the options before loading the corresponding modules, you can actually define them by the form |
I abstracted the codes in $ ble-import config/github302-perlre-server
ble/contrib/config:github30: perlre-server (1788726) has started.
$ ble/contrib/config:github302/perlre-match '<a>([^<>]*)</a>' " <a>123456789101112</a> "
$ echo $ret
15 Explanations are written in the code comments of |
@bkerin Do you have any updates on this? If I correctly understand it, is it a question/issue about the upstream Bash? |
I haven't learned anything new about the implementation in bash, I tried building bash with the option for multiple coproc support but I must have done it wrong because same error. A single coproc is ok for me at the moment as I don't use them for anything else. If I get around to adding to blesh contrib I'll try to use your setup above. This issue can be closed. |
Thank you for the reply. Hmm, I now tried the option for multiple coproc, but it seems to work in my environment both with the |
I got around to doing this and it works nicely, no more silent typo failures. One feature I wonder about though is a sort of after-everything type hook in which casual users could simply place their entire ble.sh configuration. The recommended way would become something like:
This spares the end user from having to track where things come from. I realize after-everything can be problematic (e.g. systemd have never supported) because everyone wants to be in it, but from the perspective of end users who don't want to know too much it's nice, and the only challenge is keeping devs out of it :) |
How do you define If you want to define a hook that is called after all the modules are loaded, there is still a subtlety. Some modules can be dynamically loaded in the idle state. Some modules can be loaded on demand after a long time, Some modules can be loaded by the user by running the If you want to run codes after the attaching is performed, you can use the blehook ATTACH!='<code>' If you want to run codes when most initializations (including loading of module syntax and module complete) have ended and when ble.sh is idle (i.e., when there are no additional inputs from the user), you can use # You can put the codes in a file named <filename>
ble-import -d '<filename>'
# Or if you would like to directly specify a code.
ble/util/idle.push '<code>'
# Note: In bash <= 3.2, ble.sh does not support ble/util/idle.push.
# To run the code only when `ble/util/idle.push` exists (bash >= 4.0),
# you can use `ble/function#try`.
ble/function#try ble/util/idle.push '<code>' However, the loading of the command history will be even delayed. To run the code even after the loading of the command history, you need to run the above blehook ATTACH!='ble/util/idle.push "<code>"' The calibration of ble.sh's sleep function ble/util/idle.push-background '<code>' The background processing such as ble/util/idle.push '
ble-import core-syntax
ble-import core-complete
ble/util/idle.push-background "<code>"' |
Hmm. The actual small thing that bugs me is sometimes when I create a new terminal and immediately cd somewhere, that cd command for some reason ends up in multiline mode. I can just push C-j so it's not a big deal, but somehow due to some race (I have no idea what) this occasionally happens. |
You can set This is related to the detection of pasting. When the clipboard contains text including newlines and the user mistakenly pastes the content of the clipboard, random commands can be executed. To avoid such a situation, when ble.sh considers the text is part of the pasted text, it treats the newlines as a part of the text instead of the keypress Enter. However, there is no robust way to distinguish the newline in the text from the keypress Enter, so ble.sh needs to rely on a heuristic way. When the text is sent by the terminal protocol Bracketed Paste Mode, it is always treated as a part of the pasted text. But not all the terminals support the bracketed paste mode. When the newline character is directly sent, ble.sh considers it to be a part of the pasted text if it receives the newline and many succeeding characters at the same time. At the initialization time, the initialization takes some time so that the user's input can stack, which is then received by ble.sh at the same time and causes the behavior you observe. |
Thanks, this resolves this issue nicely. |
$ echo "$BLE_VERSION"
0.4.0-devel3+cc852dc
$ echo "$BASH_VERSION ($MACHTYPE)"
5.0.17(1)-release (x86_64-pc-linux-gnu)
I think the bash behavior is better in this respect, since coproc are quite different that job-controlled jobs and should probably just silently get cleaned up. Even better would be an option in bash coproc to control this behavior and also maybe hide from jobs, but if you had to pick one I'd follow the bash behavior.
ble.sh behavior:
$ jobs 504
[1]+ Running coproc schwbrs { cat; } &
$ [ble: There are remaining jobs. Use "exit" to leave the shell.] <--- On C-d
The text was updated successfully, but these errors were encountered: