Files
lush/issues/09-prompt.md
Cormac Shannon b3aa1d9c63 Redesign prompt system: revert #09, use standard _PROMPT (issue #21)
Revert the bespoke __prompt()/__prompt2() function mechanism from issue
#09 and return to stock Lua's _PROMPT/_PROMPT2 globals (which already
support dynamic prompts via __tostring metatables). Set default
_PROMPT = "lush> " in doREPL if not already defined by config.
2026-03-04 23:53:04 +00:00

1.5 KiB

09 — Programmable prompt

Status: open Blocked by: #08

Users should be able to customize the shell prompt by defining a Lua function, similar to how other shells use PS1/PROMPT_COMMAND/precmd.

Design

  • The prompt is generated by calling a global Lua function (e.g. __prompt())
  • The function returns a string which is used as the prompt
  • If the function is not defined or errors, fall back to a sensible default

Default prompt

A built-in default prompt is provided (implemented on the C side) until the user overrides __prompt() in their config. The default could be something like:

lush>

or include the current directory:

~/Code/project>

User customization

Users override the prompt in their config (~/.config/lush/config):

function __prompt()
  return $PWD .. "> "
end

Or with colours/git info/etc:

function __prompt()
  local cwd = $PWD or "?"
  local branch = `git branch --show-current 2>/dev/null`
  local git = (branch.code == 0) and " (" .. branch.stdout:gsub("\n","") .. ")" or ""
  return cwd .. git .. "> "
end

Implementation considerations

  • The REPL loop (in lua.c) calls __prompt() before each input line
  • If __prompt is not a function or the call fails, use the default C-side prompt
  • The function runs in the normal Lua state so it has access to all globals, env vars, commands, etc.

Open questions

  • Should there be a separate __continuation_prompt() for multiline input?
  • Should the prompt function receive any arguments (e.g. exit code of last command)?