Repository navigation
Clarify how to use the PowerShell completions #695
Description
Activity
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
Reacted by Mislav Marohnić, Jan Pokorný, Tomer Figenblat, James Hollowell, dzmitry-lahoda, Krishnan S G and Bob "Wombat" Yu-Hogg@dougbu I tried running
gh completion --shell powershell |Out-String |Invoke-Expressionin my PowerShell, which produced no output. Subsequently typingghfollowed 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.Reacted by Brandon H, Thomas Levesque and dzmitry-lahoda@JanPokorny the completions themselves are seemingly incomplete. If I type
gh prthen 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 typegh.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-ghat the PowerShell prompt. It's a bit clunky and there's probably a better way to do this.Reacted by Jan Pokorný, Brandon H and Binyamin Aron Greenin my
$profilefile 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.Reacted by Mislav Marohnić, Mustafa Mohamad, Zulsorai, Bradley Grainger, Andrea Vouk, Andrei Amosov, Shubham Parihar, Kim and Daan LuttikAh, great. Thanks @bc3tech❕ (The lack of completion after
ghlikely confused me when I set this up.)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.Gotta agree, found it very odd
gh <tab>doesn't have any completionsReacted by Binyamin Aron GreenI can confirm that in git bash,
gh <tab>does complete.I can confirm that in git bash,
gh <tab>does complete.Well that would not be coming from the Powershell completion, which is the topic of this issue, since you are explicitely using BASH.
I am able to get a second level of tab expansion (as they're called in Powershell, as opposed to tab completion in bash), but not a first level. For example (note: I am not a PS expert), creating the tab completion file:
> gh completion --shell powershell > C:\Users\<user>\Documents\PowerShell\Github.Completion.ps1then sourcing it in my
$Profileto avoid the performance hit of recreating it on each launch (as others have done above):Invoke-Command -ScriptBlock { . C:\Users\<user>\Documents\PowerShell\Github.Completion.ps1 }leads me to have this work:
> gh repo <tab>-- resulting in cycling through clone, create, credits, etc. But just> gh <tab>results in the shell cycling through my directories instead of the top level items.Any suggestions?
@jasonsyoung Take a look in #1775 for a current workaround
I can't get any of the suggested solutions to work. I tried in PowerShell Core and Windows Powershell, in all cases I only have the usual file completion, no command completion. It would be nice to have an answer from the team...
- addedwindowsRelated to Windows hosts or runnersRelated to Windows hosts or runners
on Apr 27, 2021 As of 6/12/2021, with version 1.11.0, command and subcommand autocompletion are present.
I used @bc3tech 's command in my PowerShell $PROFILE, and everything seems to be working as expected. I get command autocompletion, then file autocompletion when typing after a subcommand.
Reacted by Mislav Marohnić and Kim
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:Proposed solution
Explain how to use the PowerShell completions