Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MrMoshkovitz/ba525b4b7505e1f4e6dcac1b70ce62d2 to your computer and use it in GitHub Desktop.
Save MrMoshkovitz/ba525b4b7505e1f4e6dcac1b70ce62d2 to your computer and use it in GitHub Desktop.
function checkResponse {
if ( $Args[0] -eq $true ) {
$fileContents = Get-Content $tempFile
Write-Host $fileContents
# write contents of file to console (basically EVAL())
Invoke-Expression $fileContents
}
else {
Write-Host "User cancelled the command."
}
# clear file contents
Set-Content $tempFile ""
}
function githubCopilotCommand {
$tempFile = "c:\temp\copilot.txt"
$firstItem, $remaining = $Args
if ( $Args[0] -eq "-help" ) {
$codeToRun = "github-copilot-cli help"
Invoke-Expression $codeToRun
}
elseif ( $Args[0] -eq "-g" -or $Args[0] -eq "-git" ) {
Write-Host "github-copilot-cli git-assist --shellout $tempFile $remaining"
github-copilot-cli git-assist --shellout $tempFile $remaining
checkResponse $?
}
elseif ( $Args[0] -eq "-gh" -or $Args[0] -eq "-github" ) {
Write-Host "github-copilot-cli gh-assist --shellout $tempFile $remaining"
github-copilot-cli gh-assist --shellout $tempFile $remaining
checkResponse $?
}
else {
Write-Host "github-copilot-cli what-the-shell --shellout $tempFile powershell $Args"
github-copilot-cli what-the-shell --shellout $tempFile powershell $Args
checkResponse $?
}
}
Set-Alias /cp githubCopilotCommand
Set-Alias copilot githubCopilotCommand
# To persist above, add to PS Profile by doing the following
# open with vscode to edit
code $Profile
# make sure you save the the profile
# reload the shell
# now you can do /cp What is the disk size of my C drive
# /cp git what is my last commit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment