3

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.

3
  • When you install GitHub Copilot through npm (npm install -g @githubnext/github-copilot-cli), you're likely installing a CLI (Command Line Interface) version of Copilot. This version is designed to integrate with your command line environment. Try installing it by gh extension install github/gh-copilot and then auth it with your GitHub account. I'm also a student and use copilot from the github student pack. Commented Dec 15, 2023 at 15:33
  • What you refer is copilot in the CLI preview that was set to conclude in December 15 but has been extended, however for the general public is available the Copilot in the CLI beta here docs.github.com/en/copilot/github-copilot-in-the-cli Commented Dec 15, 2023 at 15:49
  • I can actually access copilot through gh extension install github/gh-copilot, but my question is that how I can use ?? to activate it, which I think is more simple to use. Commented Dec 16, 2023 at 2:48

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

If you run into a Powershell execution issue because you just created a new profile and it is not digitally signed, here is an answer for that serverfault.com/questions/31194/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.