cli: tab-completions for powershell don't work on the root command
CLI version: 1.0.0 🚀 Related: #695
Describe the bug
gh <tab>
does not offer completions, even after runninggh completion --shell powershell |Out-String |Invoke-Expression
.- However,
gh <command> <tab>
does offer completions.
Steps to reproduce the behavior
- Open Powershell
- Type
gh
- Press tab.
- No completion occurs.
Expected vs actual behavior
Expected <kbd>gh</kbd> + <kbd>tab</kbd> to complete.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 18 (6 by maintainers)
@vilmibm I think so, too. So I opened Issue to Cobra. spf13/cobra/issues/1229
Fortunately, this bug is avoidable if only it is known to exist. Until this bug is fixed, I think it’s reasonable to write the following in the Profile.
If the pipeline is to be used, write this
I got the following to work:
I cannot reproduce with latest GitHub CLI version. We’ve upgraded Cobra in the meantime; this must have fixed it!
There are a few ways, if you want to grab the gist I posted you can use this -
Invoke-Expression -Command ([System.Net.WebClient]::new().DownloadString('https://gist.githubusercontent.com/WozNet/fcf17f71452ab9efeeb17765694b1797/raw'))
I would avoid using the code generated from -
gh completion --shell powershell
until they fix the issues I mentioned above. The error with ‘version’ means that entire grouping of commands (alias, auth, config, etc…) won’t work, and the backticks in single quotes causes there own issues.Thank you for reporting!
I made a few edits which made this a lot more workable for me, I posted the changes here - https://gist.github.com/Woznet/fcf17f71452ab9efeeb17765694b1797
I found 2 errors in the powershell completion script generated from
gh completion --shell powershell
- gh version 1.4.0 The first with[CompletionResult]::new('version', 'version', [CompletionResultType]::ParameterValue, '')
, the tooltip part cannot be empty, The second occurring when single quotes are used around backticks, as of v1.4.0 I found 31 lines with single quotes around backticks. One example is ( " - is substituted for the backticks) -[CompletionResult]::new('-a', 'a', [CompletionResultType]::ParameterName, 'Assign people by their "login"')
@strickdd I was able to reproduce it in my environment. After a lot of testing, I also found that I could avoid the error by doing this.
However, a side-effect of the code is that it causes a bug in the tail completion.
Expected
Actual
I was unsure, but I decided to put this code in
$profile
to see which would be more inconvenient.Is there a way to get partially typed words to be tab-completed?
For example:
gh pr ch<tab>
Should cycle through the following as <tab> is pressed multiple times:
gh pr checkout
andgh pr checks
Right now, it doesn’t complete anything.
Is this a cobra bug, then, or something we have control over?
@SilkyFowl Thank you for looking into all of this! ❤️
Our PowerShell completions are being generated by Cobra https://github.com/spf13/cobra/blob/master/powershell_completions.go