MacOS shell commands execute error with 1 line of output
Setup
OS: MacOS 15.4.1 Shell: zsh (via Homebrew)
❯ echo $SHELL
/opt/homebrew/bin/zsh
Shell-GPT: 1.4.5
❯ sgpt --version
ShellGPT 1.4.5
Install via pip3 with user and system override. Local llm using LM Studio.
Issue
When I test sgpt -s "find all markdown files in current folder" and choose e:
- The part highlighted in green is the first line of the correct answer
- It stop at that line
- The shell command is correct if ran manually. Following is partial screenshot:
PS: Is there ways to print out some debug messages?
Sorry, it turned out model related again.
It worked after I switched to DEFAULT_MODEL=lmstudio-community/gemma-3-12b-it-GGUF as suggested by @kth8 in #690 .
The repo with Quantization-Aware Training is lmstudio-community/gemma-3-12B-it-qat-GGUF
I tracked down the issue is due to llm reply format.
Setup to use LM Studio
In .sgptrc, I have following entry
API_BASE_URL=http://localhost:1234/v1
DEFAULT_MODEL=gemma-3-12B-it-qat-GGUF
Add debug print for shell execute
In ~/Library/Python/3.13/lib/python/site-packages/sgpt/utils.py, I added print statements in run_command
def run_command(command: str) -> None:
"""
Runs a command in the user's shell.
It is aware of the current user's $SHELL.
:param command: A shell command to run.
"""
if platform.system() == "Windows":
is_powershell = len(os.getenv("PSModulePath", "").split(os.pathsep)) >= 3
full_command = (
f'powershell.exe -Command "{command}"'
if is_powershell
else f'cmd.exe /c "{command}"'
)
else:
shell = os.environ.get("SHELL", "/bin/sh")
full_command = f"{shell} -c {shlex.quote(command)}"
print('---')
print(f'shell:{shell}')
print('---')
print(f'command:{command}')
print('---')
print(f'full_command:{full_command}')
print('---')
os.system(full_command)
Testing Result
❯ sgpt -s "find all toml files in current folder" --model nomic-ai-gpt4all-falcon
```
$ find . -name toml
```
[E]xecute, [D]escribe, [A]bort: e
---
shell:/opt/homebrew/bin/zsh
---
command:```
$ find . -name toml
```
---
full_command:/opt/homebrew/bin/zsh -c '```
$ find . -name toml
```'
---
zsh:2: command not found: $
The issue is the query result includes text other than the command.
Feel free to close this if this is not an actionable issue.