github / gh-copilot

Ask for assistance right in your terminal.
https://docs.github.com/en/copilot/github-copilot-in-the-cli
760 stars 31 forks source link

[BUG]: alias commadn nto working #52

Closed shehrozeee closed 7 months ago

shehrozeee commented 7 months ago

What happened?

installed gh copilot cli and wanted to setup alias, used the $GH_COPILOT_PROFILE = Join-Path -Path $(Split-Path -Path $PROFILE -Parent) -ChildPath "gh-copilot.ps1" gh copilot alias -- pwsh | Out-File ( New-Item -Path $GH_COPILOT_PROFILE -Force ) echo ". $GH_COPILOT_PROFILE" >> $PROFILE to setup alias as mentioned on the readme.

The alias is not configured and I now get an error when I open a new powershell image

I have checked the brackets in the gh-copilot.ps1 and they seem to be fine according to vs code syntax highlighting at least.

just to check, I copied the functions from the file and pasted them in powershell manually, it stops parsing before the last } and throws the same error

image

Versions

PS C:\Users\Shehroze> gh version gh version 2.46.0 (2024-03-20) https://github.com/cli/cli/releases/tag/v2.46.0

Relevant terminal output

PS C:\Users\Shehroze> function ghcs {

Debug support provided by common PowerShell function parameters, which is natively aliased as -d or -db

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_commonparameters?view=powershell-7.4#-debug

param( [ValidateSet('gh', 'git', 'shell')] [Alias('t')] [String]$Target = 'shell',

[Parameter(Position=0, ValueFromRemainingArguments)] [string]$Prompt ) begin {

Create temporary file to store potential command user wants to execute when exiting

$executeCommandFile = New-TemporaryFile

Store original value of GH_DEBUG environment variable

$envGhDebug = $Env:GH_DEBUG } process { if ($PSBoundParameters['Debug']) { $Env:GH_DEBUG = 'api' }

gh copilot suggest -t $Target -s "$executeCommandFile" $Prompt } end {

Execute command contained within temporary file if it is not empty

if ($executeCommandFile.Length -gt 0) {

Extract command to execute from temporary file

$executeCommand = (Get-Content -Path $executeCommandFile -Raw).Trim()

Insert command into PowerShell up/down arrow key history

Insert command into PowerShell history

$now = Get-Date $executeCommandHistoryItem = [PSCustomObject]@{ CommandLine = $executeCommand ExecutionStatus = [Management.Automation.Runspaces.PipelineState]::NotStarted StartExecutionTime = $now EndExecutionTime = $now.AddSeconds(1) } Add-History -InputObject $executeCommandHistoryItem

Execute command

Write-Host "`n" Invoke-Expression $executeCommand } } clean {

Clean up temporary file used to store potential command user wants to execute when exiting

Remove-Item -Path $executeCommandFile

Restore GH_DEBUG environment variable to its original value

$Env:GH_DEBUG = $envGhDebug } At line:1 char:15

  • function ghcs {
  • ~ Missing closing '}' in statement block or type definition.
  • CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
  • FullyQualifiedErrorId : MissingEndCurlyBrace

PS C:\Users\Shehroze> } At line:1 char:1

on opening a new powershell->

Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

At C:\Users\Shehroze\OneDrive\Documents\WindowsPowerShell\gh-copilot.ps1:8 char:15

PS C:\Users\Shehroze>

andyfeller commented 7 months ago

@shehrozeee : thank you for opening the issue and my apologies for the confusion!

I believe you're running into the problem described in #38 as the current PowerShell is 7.4+ and you are using PowerShell Desktop 5.x. There are workarounds described in #38 from other users while this is brought up for prioritization.

I'm going to close this as a duplicate of #50 for now.