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

Merged
merged 3 commits into from
Dec 17, 2024

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
@Stratus3D
Copy link
Member

Thanks for the PR @benblank ! This is great!

I left one comment on the changes but otherwise I think this is good to merge.

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.

If you know anything about automated testing of shell completions let us know. This is a pain point for this project.

Copy link
Member

@Stratus3D Stratus3D left a 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.

@benblank
Copy link
Contributor Author

If you know anything about automated testing of shell completions let us know. This is a pain point for this project.

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. 🙃

@Stratus3D
Copy link
Member

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.

@Stratus3D Stratus3D merged commit ebdb229 into asdf-vm:master Dec 17, 2024
7 checks passed
@benblank benblank deleted the fix-bash-completions branch December 17, 2024 13:41
Stratus3D added a commit that referenced this pull request Dec 18, 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.

2 participants