-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Exclude the bind -x
commands from interactive commands
#152
Conversation
The check for COMP_LINE can fail because it can be empty in the completion function for the empty command line "complete -F _func -E".
I pushed another commit, where I suggest changing $ complete -E -F _test1
$ _test1() { declare -p "${!COMP_@}"; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change makes perfect sense and certainly fixes the use-case you described. 👍
@dimo414 Could you review this PR? This fix is a very small one, so it shouldn't be difficult to review. Or is there anything missing? |
I thought about if it is possible to add a test, but we need an interactive session to directly test it. Also, the test for the existing |
@akinomyoga thanks for the PR and fix as always. 👍 Sorry for delays as I've recently had extraneous family responsibilities. Recognize there's a few open issues/PRs the community is trying to push through. I'm interested in trying to get more folks approval access to support. |
@rcaloras Thank you for taking your time!
Maybe we can write something on README.md or CONTRIBUTING.md? |
Issue: preexec is called for keybindings set up by
bind -x
Consider the following setup:
When I start a session with the above rcfile (
bashrc.exclude-bind-x
) and input "echo 1" RET C-t "echo 2" RET C-d, the result becomes this:The second
preexec
is supposed to be called against the second commandecho 2
, but it's instead called for the command of the keybindingsomething
, which is not an expected behavior.This problem was identified based on the report at atuinsh/atuin#1003 (comment).
Solution
We can take the same solution as completion functions. For the completion functions, we are using
COMP_LINE
to test whether we are currently running the completion function. For thebind -x
commands, we can testREADLINE_POINT
to test whether we are running a command for keybindings.This solution can be broken when the user sets the shell variable
READLINE_POINT
, but it's not a problem specific to this PR. The existing code forCOMP_LINE
has the same problem when the user sets the variable. In reality, there shouldn't be many cases where the user setsREADLINE_POINT
outside the keybinding functions. Rather there are more cases where the users set up keybindings throughbind -x
.Here's the behavior after this fix: