-
Notifications
You must be signed in to change notification settings - Fork 792
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
fix(completions): Address two Bash completion bugs #1770
Conversation
Thanks for the PR @benblank ! This is great! I left one comment on the changes but otherwise I think this is good to merge.
If you know anything about automated testing of shell completions let us know. This is a pain point for this project. |
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.
Approved pending one comment.
I'm vaguely aware of automated shell testing via e.g. BATS, which sounds like it could be used in some manner, but don't know enough to do anything useful without starting from scratch. 🙃 |
Yes we use BATS for general testing, but completions feel like a special case. I'll give it some thought and maybe add something later. |
Co-authored-by: Trevor Brown <[email protected]>
Summary
This PR fixes two bugs I discovered in the Bash completions for version 0.14.0. I briefly tested the Fish completions as well, but did not see either issue there.
Fixes: (I did not find existing issues for these bugs.)
Problem distinguishing between plugin names and commands
The first issue occurs when attempting to complete a command which is a substring of an installed plugin; for example, trying to complete
asdf shell
while theshellcheck
plugin is installed.Currently, the Bash completions perform a simple substring match to determine whether the previous token is the name of a plugin:
[[ "$plugins" == *"$prev"* ]]
. The string"shell"
is present in"shellcheck"
and therefore the list of plugins, so it is interpreted as a plugin name and the completion tries to get the list of installed versions. The resulting list is empty, but because" system"
is added, pressing Tab afterasdf shell
completes withsystem
.The change I've made is to wrap both the list of plugins and the previous word in spaces (the delimiters used in the plugin list) —
[[ " $plugins " == *" $prev "* ]]
. This effectively forces a full-token match, as" shell "
is not present in" shellcheck "
.Asterisk present in installed-version completions
The other issue is that the version currently in use retains its asterisk in Bash completions of installed versions. This comes from the use of
asdf list $plugin
to get the list of versions without removing the asterisk which indicates the current version. The fix simply usescolrm
to remove the first two columns of that command's output, which are always a space followed by either a space or an asterisk.Other Information
I didn't see any existing testing for command completions (I'm not sure how that would work), so no new tests cover these changes.