Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions llm_cmd.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import click
import llm
import subprocess
import os
import sys
import platform
from prompt_toolkit import PromptSession
from prompt_toolkit.lexers import PygmentsLexer
from prompt_toolkit.patch_stdout import patch_stdout
Expand Down Expand Up @@ -40,10 +43,13 @@ def interactive_exec(command):
edited_command = session.prompt("> ", default=command, multiline=True)
else:
edited_command = session.prompt("> ", default=command)
try:
output = subprocess.check_output(
edited_command, shell=True, stderr=subprocess.STDOUT
)
print(output.decode())
except subprocess.CalledProcessError as e:
print(f"Command failed with error (exit status {e.returncode}): {e.output.decode()}")
if hasattr(sys.stdin, 'isatty') and sys.stdin.isatty():
os.system(edited_command)
else:
try:
output = subprocess.check_output(
edited_command, shell=True, stderr=subprocess.STDOUT
)
print(output.decode())
except subprocess.CalledProcessError as e:
print(f"Command failed with error (exit status {e.returncode}): {e.output.decode()}")