-
Couldn't load subscription status.
- Fork 2.3k
Do not replace already existing completions #2298
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
Do not replace already existing completions #2298
Conversation
If a user has a completion defined for an alias, the alias completion script should not replace it.
d79a279 to
46033be
Compare
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.
seems legit, but what happens on a second run of bash-it? won't it ignore updates?
|
@seefood Good question, let me look into that. |
All alias completions added by this script use a wrapper which allows identifying them on reload and only replacing those. This allows users to define their own completions for aliases while still updating those added by the script on reload.
|
@seefood I pushed up a commit that should fix your concern. It does involve having to put all the alias completion functions added by the script into a wrapper so they can be identified on reload and replaced. |
|
@seefood Just wanted to bump on this. |
|
To tell you the truth, I am not entirely sure what you did there. maybe because I keep getting to it after 11pm or something. I need to read it when my brain is awake. |
d805311 to
c5caae0
Compare
|
@seefood No worries, I understand that. |
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.
seems ok, I trust you tested it... at the very worst we'll revert the PR
| # alias getting the completion added has changed. | ||
| if complete -p "$alias_name" &> /dev/null; then | ||
| # Get the -F argument from the existing completion for this alias. | ||
| aliasCommandFunction=$(complete -p "$alias_name" | rev | cut -d " " -f 2 | rev) |
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.
Shouldn't this variable be localized?
Also, I'm not sure if one can safely assume that the second last word of complete -p <alias> would be the argument of the -F option. There can be completion settings with -C <cmd> or ones without neither -F nor -C.
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.
You are absolutely right. Adding it as a local var in my next PR.
@convergedtarkus you said you fully tested this, right? Got any input regarding the complete issue raised by Koichi-san?
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.
I agree on making the variable local.
As for the logic, I think the logic is safe given that the scope is isolated.
This logic checks if the current alias being analyzed has an existing completion. If it does, this command tries to extract the name of the function associated with the completion. If the extracted name is anything but the namespace used for the aliases added by this script, that alias is skipped over because it has an existing completion function that was not added by this script. So the script only cares about aliases with existing completion functions added by this script.
Since this code is only looking for the completion commands added by this script, we can know they are created in a predictable manner. Anything else just ends up being skipped.
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.
Thank you for the explanation. I haven't carefully looked at the code around this line. Checking prefix _${namespace}:: (where namespace is alias_completion) should usually be sufficient. You can mark this conversation as marked (I'm not the PR author or a maintainer, so I don't have access to the resolve button).
Description
If a user has a completion defined for an alias, the alias completion script should not replace it.
Motivation and Context
I ad a completion for one of my alias and could not figure out why it was not working. Turns out the alias completion logic was replacing my completion. This is helpful for uses who make their own completions.
Technical Explanation
The end goal is for the alias completion script to not replace user provided completions for aliases that otherwise would have completion added by the alias completion script.
This requires a few core changes to achieve and support reload commands such as
bash-it reload.How Has This Been Tested?
I verified this with an alias that I had defined a completion for and the alias completion script was adding a completion for. Now it does not replace the one I defined.
This could also be tested by any setup where an alias has a custom completion and the alias script would add a completion for it.
Types of changes
Checklist:
clean_files.txtand formatted it usinglint_clean_files.sh.