Skip to content

Commit 2d56915

Browse files
committed
multiline command with tripple quotations
1 parent 3bb4955 commit 2d56915

File tree

2 files changed

+55
-10
lines changed

2 files changed

+55
-10
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ autocmd "find all python files modified today"
2929
autocmd "kill process on port 3000"
3030
```
3131

32+
### Multiline prompts
33+
34+
Use triple quotes for multiline prompts or prompts with quotes:
35+
36+
```bash
37+
autocmd '"""find all log files
38+
that contain "ERROR"
39+
modified in the last hour"""'
40+
41+
autocmd '"""search for files with 'important' in the name"""'
42+
```
43+
3244
## Providers
3345

3446
Supports multiple LLM providers:

src/autocmd_cli/__init__.py

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,25 @@ def setup_shell_integration() -> bool:
7474
autocmd_cmd = shutil.which("autocmd") or "uv tool run --from autocmd-cli autocmd"
7575

7676
if shell_type == "zsh":
77-
wrapper = f'\n# autocmd\nautocmd() {{ local cmd=$({autocmd_cmd} "$@"); [ -n "$cmd" ] && print -z "$cmd"; }}\n'
77+
wrapper = f'''
78+
# autocmd
79+
autocmd() {{
80+
# Handle triple quotes by preserving them as literal strings
81+
local args="$*"
82+
local cmd=$({autocmd_cmd} "$args")
83+
[ -n "$cmd" ] && print -z "$cmd"
84+
}}
85+
'''
7886
else:
79-
wrapper = f'\n# autocmd\nautocmd() {{ local cmd=$({autocmd_cmd} "$@"); [ -n "$cmd" ] && {{ READLINE_LINE="$cmd"; READLINE_POINT=${{#READLINE_LINE}}; }}; }}\n'
87+
wrapper = f'''
88+
# autocmd
89+
autocmd() {{
90+
# Handle triple quotes by preserving them as literal strings
91+
local args="$*"
92+
local cmd=$({autocmd_cmd} "$args")
93+
[ -n "$cmd" ] && {{ READLINE_LINE="$cmd"; READLINE_POINT=${{#READLINE_LINE}}; }}
94+
}}
95+
'''
8096

8197
if rc_file.exists() and "# autocmd" in rc_file.read_text():
8298
get_config_dir().mkdir(parents=True, exist_ok=True)
@@ -263,13 +279,30 @@ def main() -> None:
263279
print('autocmd: The text-to-command assistant', file=sys.stderr)
264280
sys.exit(1)
265281

266-
# Validate that user provided a single quoted prompt (not multiple unquoted words)
267-
if len(sys.argv) > 2:
268-
print("Error: Prompt must be in double quotes.", file=sys.stderr)
269-
print(f'Usage: autocmd "your prompt here"', file=sys.stderr)
270-
print(f' or: autocmd --settings', file=sys.stderr)
271-
print(f' or: autocmd --reset', file=sys.stderr)
272-
sys.exit(1)
282+
# Parse arguments - support both single quoted and triple-quoted strings
283+
user_input = ' '.join(sys.argv[1:])
284+
285+
# Check if using triple quotes
286+
if '"""' in user_input:
287+
# Extract content between triple quotes
288+
parts = user_input.split('"""')
289+
if len(parts) >= 3:
290+
# Content is between first and second triple quotes
291+
user_prompt = parts[1]
292+
else:
293+
print("Error: Mismatched triple quotes.", file=sys.stderr)
294+
print('Usage: autocmd """your multiline prompt here"""', file=sys.stderr)
295+
sys.exit(1)
296+
else:
297+
# Validate that user provided a single quoted prompt (not multiple unquoted words)
298+
if len(sys.argv) > 2:
299+
print("Error: Prompt must be in double quotes.", file=sys.stderr)
300+
print(f'Usage: autocmd "your prompt here"', file=sys.stderr)
301+
print(f' or: autocmd """your multiline prompt here"""', file=sys.stderr)
302+
print(f' or: autocmd --settings', file=sys.stderr)
303+
print(f' or: autocmd --reset', file=sys.stderr)
304+
sys.exit(1)
305+
user_prompt = sys.argv[1]
273306

274307
streaming_enabled = get_setting("streaming", "true") == "true"
275308
provider_name = get_provider_name()
@@ -286,7 +319,7 @@ def main() -> None:
286319
model = os.environ.get("AUTOCMD_MODEL") or get_setting("model") or None
287320

288321
provider = get_provider(provider_name=provider_name, api_key=api_key, model=model)
289-
prompt = f"You are a command-line assistant. Convert the user's request to a single {os.environ.get('SHELL', 'bash')} command. Output ONLY the command, nothing else - no explanations, no markdown, no options, no alternatives. Just the one best command. Note: This tool is called 'autocmd' (package: autocmd-cli), so if asked to upgrade itself, use 'uv tool upgrade autocmd-cli' or 'pip install --upgrade autocmd-cli'.\n\nRequest: {' '.join(sys.argv[1:])}"
322+
prompt = f"You are a command-line assistant. Convert the user's request to a single {os.environ.get('SHELL', 'bash')} command. Output ONLY the command, nothing else - no explanations, no markdown, no options, no alternatives. Just the one best command. Note: This tool is called 'autocmd' (package: autocmd-cli), so if asked to upgrade itself, use 'uv tool upgrade autocmd-cli' or 'pip install --upgrade autocmd-cli'.\n\nRequest: {user_prompt}"
290323

291324
if streaming_enabled:
292325
full_response = ""

0 commit comments

Comments
 (0)