Closed startakovsky closed 7 months ago
I have the same issue when doing a pipe, for instance
git diff | sgpt -s "Do a git commit with the changes"
prints the command, but does not go in an "interact mode", I guess it's because stdin is already used by the pipe so we cannot interact?
I've asked the question to ChatGPT which told me this 😅
import sys
import select
def main():
query = sys.argv[1] # get the query from command-line arguments
# Check if there's data piped into stdin
rlist, _, _ = select.select([sys.stdin], [], [], 0)
if rlist:
piped_text = sys.stdin.read()
query += ' ' + piped_text.strip() # append piped text to query
while True:
user_input = input(f"Query: {query}\nExecute or Cancel? (e/c): ").strip().lower()
if user_input == 'e':
execute_query(query)
break
elif user_input == 'c':
print("Cancelled.")
break
else:
print("Invalid input. Please enter 'e' to execute or 'c' to cancel.")
def execute_query(query):
# Your query execution code here
print(f"Executing: {query}")
if __name__ == "__main__":
main()
Added a PR here which seems to work https://github.com/TheR1D/shell_gpt/pull/356
Hi @startakovsky, thank you for reporting this issue, it should be fixed in https://github.com/TheR1D/shell_gpt/pull/439
I am doing the pipe using the
-s
flag but I do not see anything asking me to\[E\]xecute
, etc. What am I doing wrong? This is with the latest release 0.92. When I do thecat data.json | sgpt -s "curl localhost with this json"
it works just fine. So what is the difference between piping a bunch of files and a json?