Skip to content

Instantly share code, notes, and snippets.

@Jaykul
Created April 30, 2023 22:55
Show Gist options
  • Save Jaykul/664f426639341ccb454f6cebe97c36fd to your computer and use it in GitHub Desktop.
Save Jaykul/664f426639341ccb454f6cebe97c36fd to your computer and use it in GitHub Desktop.
Copilot CLI in PowerShell

We are, for now, just using the official github copilot CLI, but they didn't really have hooks for PowerShell, so I wrote a few functions to implement it.

It works great, as you can see:

a simple prompt for how to find the top 10 files

the modified query, executed

function NewTemporaryScript {
[IO.Path]::ChangeExtension(([IO.Path]::GetTempPath() + [IO.Path]::GetRandomFileName()), "ps1")
}
function InvokeTemporaryScript {
[CmdletBinding()]
param($ScriptPath)
if (Test-Path $ScriptPath) {
. $ScriptPath
Remove-Item $ScriptPath
}
}
function Request-CopilotAssist {
[CmdletBinding()]
[Alias('??','rqa')]
param([Parameter(ValueFromRemainingArguments)][string[]]$args)
$TmpFile = NewTemporaryScript
github-copilot-cli what-the-shell ('use powershell to ' + $args) --shellout $TmpFile
InvokeTemporaryScript $TmpFile
}
function Request-CopilotGitAssist {
[CmdletBinding()]
[Alias('git?','rqga')]
param([Parameter(ValueFromRemainingArguments)][string[]]$args)
$TmpFile = NewTemporaryScript
github-copilot-cli git-assist $args --shellout $TmpFile
InvokeTemporaryScript $TmpFile
}
function Request-CopilotGitHubAssist {
[CmdletBinding()]
[Alias('gh?','rqgha')]
param([Parameter(ValueFromRemainingArguments)][string[]]$args)
$TmpFile = NewTemporaryScript
github-copilot-cli gh-assist $args --shellout $TmpFile
InvokeTemporaryScript $TmpFile
}
Export-ModuleMember -Function *-* -Alias *
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment