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

Clarify how to use the PowerShell completions #695

Open
JanPokorny opened this issue Mar 24, 2020 · 5 comments
Open

Clarify how to use the PowerShell completions #695

JanPokorny opened this issue Mar 24, 2020 · 5 comments

Comments

@JanPokorny
Copy link

@JanPokorny JanPokorny commented Mar 24, 2020

Describe the feature or problem you’d like to solve

The page https://cli.github.com/manual/gh_completion explains to use the completions by adding eval "$(gh completion)" to a profile file.

For PowerShell, the equivalent command is gh completion -s powershell | iex, which produces the following error:

> gh completion -s powershell | iex
iex : At line:1 char:67
+ Register-ArgumentCompleter -Native -CommandName 'gh' -ScriptBlock {
+                                                                   ~
Missing closing '}' in statement block or type definition.
At line:1 char:31
+ gh completion -s powershell | iex
+                               ~~~
    + CategoryInfo          : ParserError: (:) [Invoke-Expression], ParseException
    + FullyQualifiedErrorId : MissingEndCurlyBrace,Microsoft.PowerShell.Commands.InvokeExpressionCommand

Proposed solution

Explain how to use the PowerShell completions

@vilmibm vilmibm added this to Backlog 🗒 in The GitHub CLI via automation Mar 24, 2020
@mislav mislav added the docs label Mar 26, 2020
@dougbu
Copy link

@dougbu dougbu commented Apr 4, 2020

I got the following to work:

gh completion --shell powershell |Out-File -FilePath gh.completion.ps1 -Encoding utf8
./gh.completion.ps1

or

gh completion --shell powershell |Out-String |Invoke-Expression
@JanPokorny
Copy link
Author

@JanPokorny JanPokorny commented Apr 17, 2020

@dougbu I tried running gh completion --shell powershell |Out-String |Invoke-Expression in my PowerShell, which produced no output. Subsequently typing gh followed by space and pressing TAB triggers file autocompletion, not command autocompletion, sadly. Does this need to be placed in $PROFILE? I was under the impression that this would (temporarily) work in a shell in which the command was ran.

@dougbu
Copy link

@dougbu dougbu commented Apr 17, 2020

@JanPokorny the completions themselves are seemingly incomplete. If I type gh pr then hit tab, I get completions for the rest of the command e.g. checkout. But, I don't get completions for anything but files if I just type gh .

W.r.t. your profile, I found the command didn't work because profiles aren't sourced. Needed the following in my profile:

New-Item function::global:Complete-gh -value { gh completion --shell powershell | Out-String | Invoke-Expression } >$null

I then execute Complete-gh at the PowerShell prompt. It's a bit clunky and there's probably a better way to do this.

@bc3tech
Copy link

@bc3tech bc3tech commented Apr 24, 2020

in my $profile file I added:

Invoke-Expression -Command $(gh completion -s powershell | Out-String)

and I get the expected result in a new powershell window. Agreed, though, I expected gh <tab> to give me some options and it does not.

@dougbu
Copy link

@dougbu dougbu commented Apr 24, 2020

Ah, great. Thanks @bc3tech (The lack of completion after gh likely confused me when I set this up.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
The GitHub CLI
  
Backlog 🗒
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.