Skip to content

Instantly share code, notes, and snippets.

@rajbos
Created March 28, 2023 10:59
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rajbos/d9519d462156e16c39c5f937d5756a69 to your computer and use it in GitHub Desktop.
Save rajbos/d9519d462156e16c39c5f937d5756a69 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
@MattJeanes
Copy link

I've made a version here that works exactly like the bash alias version: https://gist.github.com/MattJeanes/839c7adfef085f4b6001927e3eb96fd4

@rajbos
Copy link
Author

rajbos commented Apr 14, 2023

Thanks a lot @MattJeanes ! New version seems to work good 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment