Files
lush/issues/09-prompt.md
Cormac Shannon bad40fb65b Standardize issue status labels to done/open/in progress
Rename resolved→done (#1-4, #11), closed→done (#13, #18),
open (post-core)→open (#7), mark #9 as superseded by #21.
2026-03-15 19:33:49 +00:00

1.6 KiB

09 — Programmable prompt

Status: done (superseded by #21) 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)?