Repository navigation
tab-completions for powershell don't work on the root command #1775
Description
Activity
Thank you for reporting!
Reacted by Binyamin Aron Green and mooh-pooh- addedwindowsRelated to Windows hosts or runnersRelated to Windows hosts or runners
on Sep 18, 2020 [CompletionResult]::newtooltip param can't use empty string.~ ❯ gh --version gh version 1.0.0 (2020-09-16) https://github.com/cli/cli/releases/tag/v1.0.0 ~ ❯ $PSVersionTable Name Value ---- ----- PSVersion 7.1.0-preview.7 PSEdition Core GitCommitId 7.1.0-preview.7 OS Microsoft Windows 10.0.19041 Platform Win32NT PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…} PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 WSManStackVersion 3.0 ~ ❯ using namespace System.Management.Automation >> using namespace System.Management.Automation.Language >> >> [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Show help for command') >> [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Show gh version') >> [CompletionResult]::new('alias', 'alias', [CompletionResultType]::ParameterValue, 'Create command shortcuts') >> [CompletionResult]::new('api', 'api', [CompletionResultType]::ParameterValue, 'Make an authenticated GitHub API request') >> [CompletionResult]::new('auth', 'auth', [CompletionResultType]::ParameterValue, 'Login, logout, and refresh your authentication') >> [CompletionResult]::new('completion', 'completion', [CompletionResultType]::ParameterValue, 'Generate shell completion scripts') >> [CompletionResult]::new('config', 'config', [CompletionResultType]::ParameterValue, 'Manage configuration for gh') >> [CompletionResult]::new('credits', 'credits', [CompletionResultType]::ParameterValue, 'View credits for this tool') >> [CompletionResult]::new('environment', 'environment', [CompletionResultType]::ParameterValue, '') >> [CompletionResult]::new('gist', 'gist', [CompletionResultType]::ParameterValue, 'Create gists') >> [CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Help about any command') >> [CompletionResult]::new('issue', 'issue', [CompletionResultType]::ParameterValue, 'Manage issues') >> [CompletionResult]::new('pr', 'pr', [CompletionResultType]::ParameterValue, 'Manage pull requests') >> [CompletionResult]::new('release', 'release', [CompletionResultType]::ParameterValue, 'Manage GitHub releases') >> [CompletionResult]::new('repo', 'repo', [CompletionResultType]::ParameterValue, 'Create, clone, fork, and view repositories') >> [CompletionResult]::new('version', 'version', [CompletionResultType]::ParameterValue, '') CompletionText ListItemText ResultType ToolTip -------------- ------------ ---------- ------- --help help ParameterName Show help for command --version version ParameterName Show gh version alias alias ParameterValue Create command shortcuts api api ParameterValue Make an authenticated GitHub API request auth auth ParameterValue Login, logout, and refresh your authentication completion completion ParameterValue Generate shell completion scripts config config ParameterValue Manage configuration for gh credits credits ParameterValue View credits for this tool MethodInvocationException: Line | 12 | [CompletionResult]::new('environment', 'environment', [Co … | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | Exception calling ".ctor" with "4" argument(s): "Cannot process argument because the value of argument "toolTip" is null. Change the value of argument "toolTip" to a non-null value." gist gist ParameterValue Create gists help help ParameterValue Help about any command issue issue ParameterValue Manage issues pr pr ParameterValue Manage pull requests release release ParameterValue Manage GitHub releases repo repo ParameterValue Create, clone, fork, and view repositories MethodInvocationException: Line | 19 | [CompletionResult]::new('version', 'version', [Completion … | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | Exception calling ".ctor" with "4" argument(s): "Cannot process argument because the value of argument "toolTip" is null. Change the value of argument "toolTip" to a non-null value."
If set whitespace, ti works.
~ ❯ using namespace System.Management.Automation >> using namespace System.Management.Automation.Language >> >> [CompletionResult]::new('version', 'version', [CompletionResultType]::ParameterValue, '') >> [CompletionResult]::new('version', 'version', [CompletionResultType]::ParameterValue, ' ') MethodInvocationException: Line | 4 | [CompletionResult]::new('version', 'version', [CompletionResultType]: … | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | Exception calling ".ctor" with "4" argument(s): "Cannot process argument because the value of argument "toolTip" is null. Change the value of argument "toolTip" to a non-null value." CompletionText ListItemText ResultType ToolTip -------------- ------------ ---------- ------- version version ParameterValue
This bug occurs on Linux as well.
Probably the same on MacOS.PS /root> using namespace System.Management.Automation >> using namespace System.Management.Automation.Language >> >> $PSVersionTable >> >> [CompletionResult]::new('version', 'version', [CompletionResultType]::ParameterValue, '') >> [CompletionResult]::new('version', 'version', [CompletionResultType]::ParameterValue, ' ') Name Value ---- ----- PSVersion 7.1.0-preview.5 PSEdition Core GitCommitId 7.1.0-preview.5 OS Linux 4.19.104-microsoft-standard #1 SMP Wed Feb 19 06:37:35 UTC 2020 Platform Unix PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…} PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 WSManStackVersion 3.0 MethodInvocationException: Line | 6 | [CompletionResult]::new('version', 'version', [CompletionResultType]: … | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | Exception calling ".ctor" with "4" argument(s): "Cannot process argument because the value of argument "toolTip" is null. Change the value of argument "toolTip" to a non-null value." CompletionText : version ListItemText : version ResultType : ParameterValue ToolTip :
In my case, Fix
environmentandversion's CompletionResult constructor, it works!!~ ❯ gh completion -s powershell > temp:/GitHubCliCompletion.ps1 ~ ❯ # Fixed Empty stirng to Whitepace script >> . Temp:\GitHubCliCompletion.ps1 ~ ❯ # works!! >> gh issue alias api auth completion config credits environment gist help issue pr release repo version Manage issues
I got the following to work:
Invoke-Expression (@(gh completion -s powershell) -replace " ''\)$"," ' ')" -join "`n")
Reacted by Junior, Zhong Liu, Harry Wright and slaughtering@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
Reacted by SilkyFowlIs this a cobra bug, then, or something we have control over?
Reacted by SilkyFowlShould I open Issue to Cobra?
I'll have to run some errands, so I'll probably be back in half a day or so...Is this a cobra bug, then, or something we have control over?
@vilmibm I think so, too.
So I opened Issue to Cobra. spf13/cobra/issues/1229Fortunately, 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.Invoke-Expression (@(gh completion -s powershell) -replace " ''\)$"," ' ')" -join "`n") # After Bug Fixed Invoke-Expression (@(gh completion -s powershell) -join "`n")
If the pipeline is to be used, write this
gh completion -s powershell | Join-String {$_ -replace " ''\)$"," ' ')"} -Separator "`n" | Invoke-Expression # After Bug Fixed gh completion -s powershell | Join-String $_ "`n" | Invoke-Expression
Reacted by Nate Smith, Mahadi Xion and Abdur JabbarReacted by Mahadi XionReacted by Akam Foad- addedpriority-3Affects a small number of users or is largely cosmeticAffects a small number of users or is largely cosmetic
on Sep 30, 2020 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 is pressed multiple times:
gh pr checkout
and
gh pr checksRight now, it doesn't complete anything.
Reacted by SilkyFowl@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.gh completion -s powershell | Join-String { $_ -replace " ''\)$"," ' ')" -replace "(^\s+\)\s-join\s';')",'$1 -replace ";$wordToComplete$"' -replace "(\[CompletionResult\]::new\('[\w-]+)'",'$1 ''' } -Separator "`n" | Invoke-Expression
However, a side-effect of the code is that it causes a bug in the tail completion.
Expected
gh repo view -w <TAB> (Not complete )
Actual
I was unsure, but I decided to put this code in
$profileto see which would be more inconvenient.Reacted by Laurent KempéThis Issue's bug will be fixed in spf13/cobra#1208 (comment)
However, it's not yet tested whether you will be able to complete the tabs for partial words.
If there is someone who is familiar with Powershell and Go lang, please check it and it may help me to solve the bug.Note: This is not fixed in cobra v1.1.1
@Luap99 Thanks for the heads-up!
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"')Reacted by Sam CoeThis thread has dragged on a bit with various recommendations. Currently, what should we add to our powershell profile to enable completions?
nit: This issue is labeled "Windows". But PowerShell is cross-platform
This thread has dragged on a bit with various recommendations. Currently, what should we add to our powershell profile to enable completions?
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 powershelluntil 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.Reacted by Mustafa Mohamad and Andrei Amosov- addeddiscussFeature changes that require discussion primarily among the GitHub CLI teamFeature changes that require discussion primarily among the GitHub CLI team
on Apr 7, 2022 - addedneeds-investigationCLI team needs to investigateCLI team needs to investigateand removeddiscussFeature changes that require discussion primarily among the GitHub CLI teamFeature changes that require discussion primarily among the GitHub CLI team
on Apr 13, 2022 I cannot reproduce with latest GitHub CLI version. We've upgraded Cobra in the meantime; this must have fixed it!
Reacted by Galdin Raphael and SilkyFowl


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.gh <command> <tab>does offer completions.Steps to reproduce the behavior
ghExpected vs actual behavior
Expected gh + tab to complete.