Files
lush/issues/09-prompt.md
Cormac Shannon 4b49907ce7 Update project issues: resolve #02-#04, add #08-#10
Mark issues #02 (backtick lexing/parsing), #03 (command execution
runtime), and #04 (argv parsing) as resolved. Add new issues for
configuration (#08), programmable prompt (#09), and interactive
command execution (#10).
2026-02-28 18:27:55 +00:00

59 lines
1.5 KiB
Markdown

# 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`):
```lua
function __prompt()
return $PWD .. "> "
end
```
Or with colours/git info/etc:
```lua
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)?