How to use GitHub Copilot with "??"

311 Views Asked by At

Many blog show that they can use GitHub Copilot with ?? .... However, according to the official docs, you can only use it with gh copilot explain ... or gh copilot suggest ....

I have found that their difference is the way of installation:

  1. The former version is installed through npm:npm install -g @githubnext/github-copilot-cli
  2. The latter version is installed through gh extension install github/gh-copilot

I have tried to install with npm, but when I tried to auth it with my GitHub account, it told me that I'm not on the waitlist and refused. However, the waitlist doesn't exist now because this tool is in beta stage.

PS: I'm a college student, so my copilot plan is free version (included in the student pack). I'm not sure whether this matters.

1

There are 1 best solutions below

1
On

If you are looking to get the ?? functionality, you need to add a function to Powershell. It is essentially a shortcut, so instead of typing

gh copilot explain use powershell to list all txt files in temp folder

, you would use

?? list all txt files in temp folder.

To do so

  • go to powershell and type

    notepad $profile

  • add this function

    function ?? {

     $TmpFile = New-TemporaryFile
     gh copilot explain ('use powershell to ' + $args) --shellout $TmpFile
     if ([System.IO.File]::Exists($TmpFile)) { 
         $TmpFileContents = Get-Content $TmpFile
             if ($TmpFileContents -ne $nill) {
             Invoke-Expression $TmpFileContents
             Remove-Item $TmpFile
         }
     }
    

    }

copied and modified shamelessly from Scott Hanselman's blog [https://www.hanselman.com/blog/github-copilot-for-cli-for-powershell][1]

Restart powershell and you should be able to type

?? list all txt files in temp folder