github / gh-copilot

Ask for assistance right in your terminal.

Home Page:https://docs.github.com/en/copilot/github-copilot-in-the-cli

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[FEAT]: For `gh copilot suggest`, add a flag to send only the suggested command to stdout

howlowck opened this issue · comments

Describe the need

I would like a way for the copilot cli suggest command to send only the suggested command to stdout, and then terminate the process, instead of being asked to copy the command to the clipboard.

Eliminating the user interaction and sending the suggestion to stdout would also make it more programmable.

Version

Do these docs apply to a specific version?
currently using version 0.5.4-beta (2024-01-04), but should apply to all versions

Relevant terminal output

Instead of...

❯ gh copilot suggest -t shell "get pokemon id 3 information from pokemon api and pipe it to jq to get the name"

Welcome to GitHub Copilot in the CLI!
version 0.5.4-beta (2024-01-04)

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:

  curl -s "https://pokeapi.co/api/v2/pokemon/3" | jq '.name'

? Select an option
> Copy command to clipboard

Command copied to clipboard!

? Select an option  [Use arrows to move, type to filter]
> Copy command to clipboard
  Explain command
  Revise command
  Rate response
  Exit

It would just be...

❯ gh copilot suggest -t shell --non-interactive "get pokemon id 3 information from pokemon api and pipe it to jq to get the name"

curl -s "https://pokeapi.co/api/v2/pokemon/3" | jq '.name'

Going through the open issues.. I think the proposed solution in this issue can be a middle ground between forcing user interaction and issue #2 (have copilot execute the suggested code). It would effectively put the onus on the user to use the resulting command however they see fit; they can pipe the result to execute it or to save it to a file. It's up to the user.

Thanks for opening up this issue, @howlowck!

I would like a way for the copilot cli suggest command to send only the suggested command to stdout, and then terminate the process, instead of being asked to copy the command to the clipboard.

Eliminating the user interaction and sending the suggestion to stdout would also make it more programmable.

What are some use cases you are considering for making gh copilot more programmable? What are your thoughts about situations where Copilot might not be able to give you an answer?

Another idea is that is similar is too. Add --copy flag so all you have to do is paste after it has run, reducing input required and --copy I would just put into my ghcs and ghce aliases so I can have it always behave that way.

Another idea is that is similar is too. Add --copy flag so all you have to do is paste after it has run, reducing input required and --copy I would just put into my ghcs and ghce aliases so I can have it always behave that way.

Thanks for beating me to the punch, @rlove, and already upgrading to v1.0.0! ✨ So a few things I was thinking about regarding this issue up to GA:

ghcs works like the technical preview of executing commands in the context of the shell that invoked the experience using the gh copilot suggest --shell-out flag. Everything about gh copilot outputs to stdout, it's how most CLIs work, so you could use this flag.

All of that said, GitHub Copilot in the CLI is not currently designed for or intended to be used in an automated fashion as being discussed. Ideally there would be a Copilot SDK or library for people who want to build an automated experience. The challenge is that most conversational chat involves human interaction and multiple rounds of revision.

Please add this, since I can't execute commands in Fish, this would at least let me pipe the command into my shell.

I'm interested in just the first part, getting the suggestion, but not necessarily the programmable part. I hope that programmability aspect isn't a reason that this suggestion is ignored.

Being able to only get the suggested command has useful productivity aspects, it's a quick lookup helper that gets out of your way.

More often than not I'd like to use Copilot CLI to just get the suggestion and use that as a jumping-off point. I don't really need a perfectly precise result, it is after all just a suggestion.

$ gh copilot suggest --non-interactive -t shell "How do I get all the ECS Fargate tasks running in a cluster?"
<blah blah blah> 
aws ecs list-tasks --cluster <cluster-name> --launch-type FARGATE

I am currently having to get the suggestion, and then ⬇️⬇️⬇️⬇️⬇️ interactively exiting, each time I use the tool.