-
Couldn't load subscription status.
- Fork 2.3k
Improve array handling in alias completion #2293
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
Improve array handling in alias completion #2293
Conversation
The old approach would cause the alias_arg_words array to be incorrectly
converted to a string leading to a command like git branch -D
being converted into ('git' 'branch -D') which was incorrect. The new
approach keeps each argument separate leading to ('git' 'branch' '-D')
which produces correct completion.
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.
is it necessary to go through this extra printf? I would think just switching [*] to [@] might have worked too? please try to do this a bit cleaner maybe, or at least make like 84 use a local var and calculate it down by the other line. the distance between the two doesn't make sense to me, unless I missed something.
|
@seefood The For example: That outputs Notice that the I can definitely look into cleaning up how this is done though! |
|
The CI failure does not look like it is related to my changes. I'm seeing commits in master that have the same issues where some tests appears to not be running. |
This correctly quotes and escapes characters to be shell safe. This also requires wrapping the result in rather than '' to avoid problems with escaping single quotes.
This causes incorrect escaping of characters. %q handles all cases that need to be handled including mulitple words in one array entry
|
@seefood @akinomyoga Just wanted to bump on this for reviews. |
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.
looking good!
Description
I was seeing issues where certain aliases do not complete as expected.
For example, my
alias gbD='git branch -D'alias should provide completions to local branches only, and it does when run without an alias. However when running completion on the alias, I get all the branches which appears to be the git default completion response.I tracked this down to an issue where an array was being incorrectly handled. The old handling caused this result,
COMP_WORDS=[‘git’, ‘branch -D’, 'ma'](length 3) wherebranchand-Dwere combined into a single entry. This produces the incorrect behavior. By changing the array to string handling to better maintain individual arguments the new result isCOMP_WORDS=[‘git’, ‘branch’ ,‘-D’, 'ma'](length 4) which correctly keepsbranchand-Dapart.Motivation and Context
This improves alias completions to act more correctly.
How Has This Been Tested?
I have been unable to create a unit test that is able to call the alias completion function. I have tested this manually on my machine and it works as expected.
An easy way to manually test this is to add the
alias biea='bash-it enable alias'and load bash-it with the bash-it completion enabled. Without my fix the complete for this alias are the base level bash-it commands such as doctor, version etc. With my change the output is the aliases that can be enabled as would be expected.Screenshots (if appropriate):
N/A
Types of changes
Checklist:
clean_files.txtand formatted it usinglint_clean_files.sh.