-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Feat: Add zsh, fish and PowerShell completion support #8122
Feat: Add zsh, fish and PowerShell completion support #8122
Conversation
Looks good to me -- I added @anthonyfok as a reviewer, as I remember vaguely that he was "talking about this" at some point. |
Bump, I would love to see this merged. /cc @anthonyfok @benmezger I assume you have confirmed that this actually work? |
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.
Hello! The patch itself looks good, but probably more work is needed, in separate commits.
-
Zsh completion works. I placed the generated file in "${fpath[1]}/_hugo" (according to https://github.com/spf13/cobra/blob/master/shell_completions.md), i.e. /usr/local/share/zsh/site-functions/_hugo on my system.
-
Fish completion probably works, but somehow fish already comes with its own hugo completion in /usr/share/fish/completions/hugo.fish, and for some reasons completion still works after removing that file.
What needs to be done, probably as separate commits:
-
PowerShell completion does not work due to old version of Cobra being listed in go.mod.
PowerShell support was added to Cobra on 2020-12-29, but the latest released version of Cobra v1.1.1 is dated October 2020, thus PowerShell completion is not working (fish completion is output instead.), so probably Cobra needs a new release, and Hugo's go.mod needs to be updated accordingly. -
hugo gen autocomplete
writes to /etc/bash_completion.d/hugo.sh by default regardless of shell--type
unless--completionfile
is defined.
I have always uneasy on this behaviour (which dates way back to the early days of Hugo) especially /etc is not supposed to be writeable by normal (non-admin) users. But yes, writing zsh/fish/PowerShell completion file as /etc/bash_completion.d/hugo.sh is definitely incorrect, so this needs to be fixed somehow, probably in a separate PR/commit.
If the two problems I listed above are better served by separate pull requests, I can change the review stations from "requested changes" to "approved". Please let me know. :-) |
@anthonyfok, thanks for the input, I have some questions regarding the issues you mentioned.
|
No. I think keeping PowerShell support is good. What needs to be done is that we should release Cobra v1.1.2 or 1.2.0, and have Hugo depend on the new Cobra version, so the PowerShell completion generation would work. I will look into it.
I agree: printing to So, yes, please feel free to go ahead with making this change! |
I suggest we take the Powershell thing as a separate ... thing. |
I was wrong... even with the latest Cobra (master, or "github.com/spf13/cobra v1.1.2-0.20210126175524-9df156e6d11e"), PowerShell autocompletion generation still doesn't work: it is still generating a fish file instead on my end. And actually Cobra v1.1.1 does have PowerShell support; the latest commits after v1.1.1 merely enhances it. My previous hypothesis was all wrong. Sorry! @bep, @benmezger, is PowerShell completion working for you at all?
Good idea! I didn't even know that Cobra has support for PowerShell completion, haha! |
@anthonyfok I've made the suggested changes. If you have any suggestion on handling |
@anthonyfok feel free to merge, it looks good to me. I'm not a big Powershell (or Windows user; I have an old Windows 8.1 VM that I test Hugo stuff on (only version I have license for :-), not sure it even has Powershell...). @benmezger a quick note: the doc below /commands gets autogenerated so any manual change to it will be overwritten. It does not matter too much here, but I'm just mentioning it. |
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.
Looks good to me, and all tests work out! I love how it ouputs to stdout
by default.
Thank you @benmezger for the great work!
@anthonyfok for the future it would be good if you could squash commits like these into one (it's one logical unit). |
@bep Indeed! Thank you for the advice! I noticed the "3 separate commits that should have been one" too late, and wished I could have gone back and fixed it, and yet the "squash commit" option didn't even cross my mind! My inexperience. Will definitely be more careful in future PRs. Thank you! |
@bep @anthonyfok I should have noticed it too. It didn't occur to me that the |
Revert "Refactor: Remove powershell support" with fixes Thanks to Ben Mezger (@benmezger) for the original code. See #8122 This reverts commit a7c515e.
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This PR adds support for zsh and fish completion.
See issue #4296