Code Monkey home page Code Monkey logo

copilot-cli-powershell's Introduction

copilot-cli-powershell

The official Github Copilot CLI has no direct Windows/Powershell support.
This script substitutes the official project to make it easier to use on Windows. It is adapted from a Discord thread in the Github-Next Discord Server.

I am not a good Powershell Dev in any way. If someone wants to take this over or contribute, you are very welcome.

This project is not affiliated with Github or Microsoft.

Installation

First, make sure you have NodeJS v16+ installed and install the Official GitHub Copilot CLI:
npm install -g @githubnext/github-copilot-cli (or yarn/pnpm equivalent if you prefer using those to manage your NodeJS packages)
Then run github-copilot-cli auth and follow the instructions.

Then you can install this script from the PowerShell Gallery:
Install-Module -Name copilot-cli-powershell
Next, open your Powershell Profile file (e.g. via code $PROFILE) and add a line with the Text
Set-GitHubCopilotAliases
(Or, if you're experiencing issues, use the passive mode instead: Set-PassiveGitHubCopilotAliases)
Finally, restart powershell and invoke Copilot by using ?? Type what Command you want here!
or git? Type what git-specific Command you want here!
or gh? Type what github-cli-specific Command you want here!

Normal vs Passive mode

TLDR:

Passive mode will simply register ??, git? and gh? as command aliases that start copilot-cli.

Normal mode will hook into powershell to listen for Enter keypresses to replace the command with an escaped version before powershell parses it to also capture characters like ", ;, |
Normal mode will break if another script also tries to hook the Enter key.

/TLDR

Powershell tries to parse typed commands to provide functionality like:

  • output piping (via "|")
  • multiple commands in one line (via ";")
  • multiple lines for one command (via automatically detecting unbalanced quotes and brackets)

This however also means that using copilot-cli with an instruction that contains any of these special characters won't work.
For example:
?? Join all words from the Get-Verb command with ", "
will be transformed into the instruction
Join all words from the Get-Verb command with ,
and
?? List all png files; sort them by size
will be transformed into the instruction
List all png files and a separate command sort them by size (which likely errors since sort isn't a command/binary)

Normal mode is potentially problematic as PSReadLine currently has no support for multiple Key Handlers (not even for retrieving key handlers before replacing them so we can call them later).
This means that, if another script is also hooking the Enter key using Set-PSReadLineKeyHandler, only one of the two key handlers will actually run, breaking either this script or the other one.

copilot-cli-powershell's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

yustier skint007

copilot-cli-powershell's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.