Skip to content

feat(prompt): support shell scripts in PROMPT1/PROMPT2 (psql parity) #744

@NikolayS

Description

@NikolayS

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.rs or wherever prompt is rendered — find the prompt interpolation function
  • Add a render_prompt_backtick(cmd: &str) -> String helper
  • Use std::process::Command to 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions