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).
This commit is contained in:
58
issues/09-prompt.md
Normal file
58
issues/09-prompt.md
Normal file
@@ -0,0 +1,58 @@
|
||||
# 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)?
|
||||
Reference in New Issue
Block a user