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: support asdf shim-versions completions in fish & bash #1554

Merged
merged 5 commits into from
May 31, 2023
Merged

fix: support asdf shim-versions completions in fish & bash #1554

merged 5 commits into from
May 31, 2023

Conversation

MageJohn
Copy link
Contributor

@MageJohn MageJohn commented May 3, 2023

Summary

I noticed that fish didn't have completion for the shim-versions subcommand, so I went to add it. While doing so I also added the command to the bash completion.

While testing the completion I noticed that my ls alias (which uses exa and adds icons) was being picked up by the completion system, breaking it; I've fixed that too.

Finally, the bash completion for which and shim-versions suggested all possible commands on the system, rather than just the shims like the completion in other shells, so I've changed that.

@MageJohn MageJohn requested a review from a team as a code owner May 3, 2023 10:58
@hyperupcall
Copy link
Contributor

Thank you for your contribution! I have added some comments to the code.

@MageJohn
Copy link
Contributor Author

@hyperupcall thanks for checking out my PR! Unfortunately I can't see any comments, I could just be missing something however.

@hyperupcall
Copy link
Contributor

@MageJohn Under Files Changed or if you scroll up on this issue, you should be able to see them? If you don't then you might want to switch to the official client or view this pull request directly on github.com

# shellcheck disable=SC2207
COMPREPLY=($(compgen -c -- "$cur"))
COMPREPLY=($(compgen -W "$(basename "$asdf_data_dir"/shims/*)" -- "$cur"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On my computer, basename seems to complain with "extra operand" errors if there are multiple path arguments and the flag -a or --multiple are not passed. I'm not sure how common these flags are on different platforms

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There also appears to be an issue with nullglobs. If no files are found in /shims, basename prints a "missing operand" error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch on these. I did a little research on basename and it looks like support for a -a flag does vary by system, so to be safe I've used a loop. I've also fixed the empty glob issue by enabling the nullglob option (in a subshell to avoid contaminating the users environment).

@@ -47,7 +47,7 @@ function __fish_asdf_plugin_list_all
end

function __fish_asdf_list_shims
ls $asdf_data_dir/shims
basename $asdf_data_dir/shims/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to use Fish's path builtin here? At first glance path basename doesn't seem to have the same problems as /usr/bin/basename

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There also appears to be an issue with nullglobs. If no files are found in /shims, basename prints a "missing operand" error. In Fish, you can work around this by setting the out to a variable first set files $asdf_data_dir/shims/*, then using files.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one, I hadn't noticed the path builtin yet. Using path basename solves the nullglob issue as well.

One thing to note is that the path builtin is relatively new, introduced in version 3.5 last year. That said, fish is usually always installed by users rather than being part of the OS, which means it's more likely to be up to date. Add that to the fact that completions are non-critical for asdf to function, I think it's safe for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point - we're still figuring out which versions of which shells to support in #1436. 3.5 is available on Fedora 38 and 37, but not Debian 11 Bullseye or Ubuntu 22.04. @jthegedus might have a better idea about the versions of Fish we have historically supported

Copy link
Contributor Author

@MageJohn MageJohn May 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While using path basename in this situation is convenient, there's no reason a loop (like for the bash implementation) wouldn't work if the decision is that older fish versions need to be supported. @jthegedus let me know what your decision is, and if needs be I'll happily change the implementation.

@hyperupcall
Copy link
Contributor

hyperupcall commented May 27, 2023

Thank you - it was a mistake on my side 🤦

I started a review and I forgot to "submit it" 😛

@MageJohn
Copy link
Contributor Author

Nice, I can see the comments now! Thanks for the review, I've addressed the feedback.

@jthegedus jthegedus changed the title Add completion in fish & bash for asdf shim-versions fix: support asdf shim-versions completions in fish & bash May 28, 2023
Yuri Pieters added 3 commits May 28, 2023 18:58
`ls` is meant for users, so the output isn't meant to be suitable for scripts.
Users may have aliases that change the output of the command, such as
adding icons.
@MageJohn MageJohn requested a review from hyperupcall May 28, 2023 18:06
Rather than completing all available commands, only complete the shims
provided by asdf. This aligns with the completion in other shells.
@hyperupcall
Copy link
Contributor

hyperupcall commented May 28, 2023

LGTM! I don't have permission to run the workflows or merge, but @jthegedus can and he can tell us if we support Fish versions below 3.5 or not.

@jthegedus
Copy link
Contributor

jthegedus commented May 31, 2023

can tell us if we support Fish versions below 3.5 or not.

We now target Fish v3.6.1 in our CICD pipeline, as per

fish_semver="3.6.1"

Not sure if we should be testing against multiple shell versions.

And just because we test against one version does not mean it is the minimum supported version (something I would like to track in #1435 as well)


My understanding is that since Fish is pre 1.0.0 that most people are updating to the latest as soon as they're aware it's available. Probably a bad assumption if people are using Homebrew 🤷

As pointed out, we can certainly support an older version with more code, but ideally we would comment such code to signal to future contributors that it is specifically to support older versions. I would prefer we just merge this and then if older version users have problems, retrofit the code with comments then.

Copy link
Contributor

@jthegedus jthegedus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! As per other comments, we can make specific changes to support older versions should that be a problem for any users unwilling to update to the latest Fish version.

@jthegedus jthegedus merged commit 99623d7 into asdf-vm:master May 31, 2023
@MageJohn MageJohn deleted the shim-versions-completion branch May 31, 2023 12:27
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.

3 participants