Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

benblank
Copy link
Contributor

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 the shellcheck 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 after asdf shell completes with system .

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 uses colrm 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.

@benblank benblank requested a review from a team as a code owner July 28, 2024 18:42
@benblank benblank changed the title Fix Bash completions fix(completions): Address two Bash completion bugs Jul 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant