fix(completions): Address two Bash completion bugs #1770
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.