TheR1D / shell_gpt

A command-line productivity tool powered by AI large language models like GPT-4, will help you accomplish your tasks faster and more efficiently.
MIT License
8.84k stars 696 forks source link

Pasting from clipboard into --repl mode does not handle new line characters #505

Closed erikd234 closed 3 months ago

erikd234 commented 4 months ago

Pasting from clipboard into --repl mode does not handle new line characters

For example lets pretend we have the following in clipboard

"this is a bunch of text \n with many newline characters \n"

sgpt --repl chat

>> <ctrl+shift+v>

When we do the above and paste it only one line at a time is paste and sgpt will break up the input into as many prompts as new line characters for example

>> this is a bunch of text

response from sgpt

>> with many newline character

response 2

This makes it really hard for me to productivy use the --repl mode to modify code and text when I want to frequently copy and paste.

I have two work arounds that I dont like

  1. set a new keybind that strips the newline characters before pasting
  2. exit out of repl mode each time and use xclip to paste the prompt in

Can we make the --repl interface accept pastes with newline characters???

if there is a way i am happy to contribute and give the enhancment a shot. Just let me know if you would accept a PR with this feature and if you think this feature is possible (i have not read the codebase in detail yet for how the --repl interface is handled)

thanks.

TheR1D commented 3 months ago

As it is mentioned in README.md, there is an option to provide multiline prompts using triple quotes """:

sgpt --repl temp
Entering REPL mode, press Ctrl+C to exit.
>>> """
... Explain following code:
... import random
... print(random.randint(1, 10))
... """
It is a Python script that uses the random module to generate and print a random integer.

So in this case, you can enter REPL mode, type """ + enter and then paste <ctrl+shift+v>.