-
Notifications
You must be signed in to change notification settings - Fork 8
feat(prompt): support shell scripts in PROMPT1/PROMPT2 (psql parity) #744
Copy link
Copy link
Closed
Description
Problem
psql supports shell command substitution in prompts via ````command```:
PROMPT1='`hostname`:\u@\h:\d> '
PROMPT2='... '
rpg does not execute the backtick-quoted commands — it renders them literally. This was reported by the pspg author (issue #703), who relies on this feature.
Spec
Match psql behaviour:
- In PROMPT1/PROMPT2, detect
command(backtick-delimited) - Execute the command via shell, capture stdout
- Substitute the output (trimmed) into the prompt string
- Execute once per prompt render
- If the command fails or is empty, substitute empty string (no crash)
Also verify other prompt escape sequences work correctly:
%u— username%h— host%d— database%>— port%#— # for superuser, > otherwise%R— query buffer state
Implementation hints
src/repl/mod.rsor wherever prompt is rendered — find the prompt interpolation function- Add a
render_prompt_backtick(cmd: &str) -> Stringhelper - Use
std::process::Commandto run the shell command - Security: run exactly the command the user configured — no additional sandboxing (same as psql)
Acceptance criteria
PROMPT1='\hostname`:\u@\h:\d> '` renders correctly with actual hostname- Multi-command prompts work
- Failed commands produce empty substitution, not a crash
- Tests cover: valid command, failing command, empty output, no backtick (regression)
- Existing prompt tests pass
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels