Powershell Profile fails with interactive prompt
Describe the bug
following your video guide posted here video guide here you run gh copilot alias --help and use the example for adding to powershell profile
# Add aliases to PowerShell profile
$ $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
running these for the first time (as suggested as a first step in the video) results in interactive prompt being added to that file which then break the command string and actually overwrites $profile
these are added to the gh-copilot.ps1 file.
? Allow GitHub to collect optional usage data to help us improve? This data does not include your queries. [Use arrows to move, type to filter]
> Yes
> No
? Allow GitHub to collect optional usage data to help us improve? This data does not include your queries.
> Yes
Also i may have missed this but i dont see a requirement to have powershell 7.3 but your using a "Clean" block in the gh-copilot.ps1 which was only added in 7.3. I may have missed that requirement though
Steps to reproduce the behavior
- download CLI, authenticate
- run gh copilot alias --help
- run the command examples for powershell
Expected vs actual behavior
alias's are added to profile
@craftzneko : thank you for opening this issue and apologies for any frustration this may have caused! ❤
I believe there are other issues we are tracking similar feedback already:
- #40
- #50
How would you suggest modifying the aliases for older PowerShell 7.x releases?
@andyfeller my apologies i originally logged this over on the general gh repo and did search first but they then suggested I post here and I didn't search for existing issues open on this repo. If you want to target powershell desktop 5 you would need to refactor the code to remove commands not in 5 such as "Clean" block, assuming the actual extension will even work on 5. If it doesnt work on 5 i guess just put an if to check and prevent potentially breaking a users profile if they try and run it from 5
if ($PSVersionTable.PSVersion.Major -eq 5) {
Write-Output "Ending as running in powershell 5"
}
I've also just installed GHC for the first time using https://docs.github.com/en/copilot/managing-copilot/configure-personal-settings/configuring-github-copilot-in-the-cli#powershell and have hit this error and couple others, running pwsh v7 on macos,
$PSVersionTable.PSVersion.Major
7
this is the error on start after adding to the pwsh profile using the standard command from microsoft docs,
ParserError: /Users/mattduguid/.config/powershell/gh-copilot.ps1:63
Line |
63 | clean {
| ~~~~~
| unexpected token 'clean', expected 'begin', 'process', 'end', or 'dynamicparam'.
checking contents of file gh-copilot.ps1 i see this interactive text from the setup added to the top of the file which shouldnt be there so removed that,
7[?25l8[0G[2K
? Allow GitHub to collect optional usage data to help us improve? This data does not include your queries. [Use arrows to move, type to filter]
> Yes
No
7[1A[0G[1A[0G8[?25h8[0G[2K[1A[0G[2K[1A[0G[2K[1A[0G[2K[1A[0G[2K
? Allow GitHub to collect optional usage data to help us improve? This data does not include your queries.
> Yes
to fix the first "clean" block error i moved the contents up to the "end" block.
i then get a new "clean" block errror,
ParserError: /Users/mattduguid/.config/powershell/gh-copilot.ps1:95
Line |
95 | clean {
| ~~~~~
| unexpected token 'clean', expected 'begin', 'process', 'end', or 'dynamicparam'.
this one didn't have an end block so renamed the "clean" to "end" and starts without error now.
tested both a "suggest" and an "explain" after that and works,
PS /Users/mattduguid> ghcs “install git”
Welcome to GitHub Copilot in the CLI!
version 1.0.4 (2024-06-13)
I'm powered by AI, so surprises and mistakes are possible. Make sure to verify any generated code or suggestions, and share feedback so that we can learn and improve. For more information, see https://gh.io/gh-copilot-transparency
Suggestion:
sudo apt-get install git
? Select an option
> Exit
PS /Users/mattduguid> ghce “trace route github.com”
Welcome to GitHub Copilot in the CLI!
version 1.0.4 (2024-06-13)
I'm powered by AI, so surprises and mistakes are possible. Make sure to verify any generated code or suggestions, and share feedback so that we can learn and improve. For more information, see https://gh.io/gh-copilot-transparency
Explanation:
• traceroute is used to trace the route that packets take from the source to the destination.
• github.com is the destination hostname or IP address.