-
Notifications
You must be signed in to change notification settings - Fork 95
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
Preexec runs before accepting the command line when using readline shell command bindings. #100
Comments
This issue is very similar to this one: #27 |
Do you have any thoughts for how bash-preexec could better handle this situation? I don't think a consensus was reached in #27. |
My immediate thought was to use some of the variables that are set when readline widgets are executed ( I have read the bash manual to look for other suitable variables but I couldn't find any. I needed to solve this in my project. (https://github.com/curusarn/resh) Needless to say, this is nor very safe nor usable in the general case. It breaks if someone uses their own custom readline functions/widgets (luckily this is not common). Not all projects can get away with invoking the hooks repeatedly. I have just messaged the bug-bash@gnu.org mailing list to ask them if there is a way to determine why the DEBUG trap was triggered. If it was invoked because of "real" interactive command or because of custom readline function/widget. |
This is a reply I got from Chet Ramey: On 3/15/20 7:41 AM, Šimon Let wrote:
Since the DEBUG trap happens before the command executes, it's not a real
They're not set when the the DEBUG trap runs before, say, a shell
No.
I'd have to see a compelling reason to implement them. Chet |
The most important part is that there is no way to tell why was the DEBUG trap triggered. It seems that there are two options:
|
It's worth remembering that bash-preexec is attempting to implement support for pre/post on top of a shell that doesn't provide this functionality (as Chet said). There will likely always be gaps in functionality because of this Bash design decision, and if Bash ever provided proper hooks this project would no longer be needed[1]. Certainly if you can identify a reasonable combination of hooks that get what you need without regressing other user experiences it might be possible to improve bash-preexec, but you'd likely be in the best position to drive that. [1]: But even if a new Bash version implemented hooks people will be running older Bash versions for the foreseeable future, so making changes to Bash itself won't help most users for a fairly long time. |
I think this issue might be solved by #152 - the updated version works for me, keybindings set up with |
I think you are right. The problem reported here should be fixed by #152. |
Readline allows us to bind arbitrary shell commands to key sequences using
bind -x
. Using these shell commands results inpreexec()
being executed before accepting the command line instead of after. Pluspreexec()
is executed with the same argument twice effectively skipping the next accepted command-line.Example
preexec()
andprecmd()
Control+X
Control+X
We can see that
preexec()
was run before we accepted the command line. We can also notice thatpreexec()
run with the same argument as moments before.Enter
to accept the command typed by readlineWe can see that
preexec()
wasn't executed this time effectively skipping the command-line typed by readline.typed by readline printing the prompt (ins)[simon@simon-pc ~]$
The text was updated successfully, but these errors were encountered: