Created
March 28, 2023 10:59
-
-
Save rajbos/d9519d462156e16c39c5f937d5756a69 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
I've made a version here that works exactly like the bash alias version: https://gist.github.com/MattJeanes/839c7adfef085f4b6001927e3eb96fd4