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
tab-completions for powershell don't work on the root command #1775
Comments
Thank you for reporting! |
~
❯ 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. 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 ~
❯ 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") |
@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 |
Is this a cobra bug, then, or something we have control over? |
Should I open Issue to Cobra? |
@vilmibm I think so, too. Fortunately, this bug is avoidable if only it is known to exist. 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 |
Is there a way to get partially typed words to be tab-completed? For example: Should cycle through the following as is pressed multiple times: Right now, it doesn't complete anything. |
@strickdd 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. Expectedgh repo view -w <TAB>
(Not complete ) ActualI was unsure, but I decided to put this code in |
This Issue's bug will be fixed in spf13/cobra#1208 (comment) |
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 |
This 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 |
There are a few ways, if you want to grab the gist I posted you can use this - I would avoid using the code generated from - |
I cannot reproduce with latest GitHub CLI version. We've upgraded Cobra in the meantime; this must have fixed it! |
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
gh
Expected vs actual behavior
Expected gh + tab to complete.
The text was updated successfully, but these errors were encountered: