Sunday, July 14, 2024
HomeTechnologySoftwareGitHub Copilot CLI for PowerShell

GitHub Copilot CLI for PowerShell


GitHub Next has a cool project that is basically Copilot for CLI (Command Line Interface). You can sign up for their waitlist at: Co-pilot of the CLI site.

Copilot for CLI provides three shell commands: ??, git? and gh?

This is cool, but I use PowerShell. So this is it? The instructions are just router instructions to a larger EXE called github-copilot-cli. So if you select “??something”, you are essentially selecting “what the hell is github-copilot-cli”.

So this means I should be able to do the same/similar alias for my PowerShell prompt and change the injected prompt (look at me, I’m a prompt engineer) to add “use powershell”.

It’s not perfect now, but hopefully it will make the Copilot CLI team understand that PowerShell needs some love too.

This is my alias. If these suck, feel free to make suggestions. Please note that “user powershell to” has been added for?? Can I make one? and apps? One of them executes bash and one executes PowerShell. I can also make it use wsl.exe and shell bash. There are many possibilities.

function ?? { 
$TmpFile = New-TemporaryFile
github-copilot-cli what-the-shell ('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
}
}
}

function git? {
$TmpFile = New-TemporaryFile
github-copilot-cli git-assist $args --shellout $TmpFile
if ((System.IO.File)::Exists($TmpFile)) {
$TmpFileContents = Get-Content $TmpFile
if ($TmpFileContents -ne $nill) {
Invoke-Expression $TmpFileContents
Remove-Item $TmpFile
}
}
}
function gh? {
$TmpFile = New-TemporaryFile
github-copilot-cli gh-assist $args --shellout $TmpFile
if ((System.IO.File)::Exists($TmpFile)) {
$TmpFileContents = Get-Content $TmpFile
if ($TmpFileContents -ne $nill) {
Invoke-Expression $TmpFileContents
Remove-Item $TmpFile
}
}
}

It then also provides suggestions for running the command. Very smooth.

image

Hope you like it. There are a lot of interesting things happening in this space.




About Scott

Scott Hanselman is a former professor, former financial chief architect, current speaker, consultant, father, diabetic, and Microsoft employee. He was a failed stand-up comedian, a speculator and a book author.

Facebook
Twitter
subscription
about communication

organizer
Hosted in Azure App Service








RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments