Commit Graph

19 Commits

Author SHA1 Message Date
Cormac Shannon
51b39930ed Fix lush tests to work from testes/ directory (via all.lua)
Tests hardcoded ./lua and assumed CWD was the project root.
Add shared testutil.lua module to derive interpreter path from
arg table, and use temp directories for glob tests instead of
relying on .c files in CWD.
2026-03-22 23:17:17 +00:00
Cormac Shannon
cca6749d4d Rename lush Lua API: command→capture, subcmd→run, getenv→envget, setenv→envset
Lua-facing names only; C internals unchanged.

  lush.capture(str)     — return {code, stdout, stderr} table
  lush.run(str)         — return stripped stdout string
  lush.interactive(str) — run with TTY, set _, return result
  lush.envget(name)     — get environment variable
  lush.envset(name,val) — set environment variable
2026-03-22 18:58:59 +00:00
Cormac Shannon
917509aa8a Refactor lush tests: remove duplication, fill coverage gaps, wire into all.lua
- Wire all 11 lush test files into testes/all.lua (was only 4)
- Delete dead commands-interactive.lua (disabled via os.exit(0))
- Remove duplicate regression test from piping.lua
- Add user-defined command tests (lush.commands): basic, int return,
  table return, error handling, removal, API call
- Add lush.subcmd() and lush.interactive() direct call tests
- Add argv edge cases: single-quote backslash, \$ escape, unknown
  escape, adjacent quote concatenation
- Add globbing edge cases: brace suffix, no-comma braces, bracket
  glob, mid-word tilde passthrough
- Add signal exit code test (128+9=137)
- Add escaped-pipe and empty interactive command tests
2026-03-22 17:58:09 +00:00
Cormac Shannon
68a5273094 Add shell aliases via lush.aliases table (issue #28)
Aliases rewrite the command string before pipeline splitting, so alias
values may contain pipes (e.g. lush.aliases.foo = "echo hi |"). Expansion
happens once per dispatch to prevent recursion.
2026-03-20 22:58:01 +00:00
Cormac Shannon
02df45b18f Fix config/prompt tests to use config.lua extension
The tests wrote config as `lush/config` (no extension) but
handle_lushconfig() looks for `config.lua` or `config.lush`.
2026-03-18 09:54:18 +00:00
Cormac Shannon
768de9fe8b Expose lush global as a standard library (issue #26)
Register luaopen_lush() in stdlibs so the lush table is available as a
global. Users can now extend the shell by adding functions to
lush.builtins. The OP_LUSH VM access via integer keys is preserved.
2026-03-18 09:52:56 +00:00
Cormac Shannon
1766e40a68 Implement $(cmd) subcommand syntax in commands (issue #27)
Add $() for inline subcommand substitution that runs a command and
inserts its stdout (trailing newlines stripped) into the outer command
string. Supports nesting, and mixing with ${expr} and $NAME.
2026-03-18 09:29:51 +00:00
Cormac Shannon
42baabde34 Implement $VAR expansion in commands (issue #25)
Extend read_command_body() to detect $NAME and trigger interpolation
using the same fragment-split mechanism as ${expr}. The lexer collects
the identifier into cmd_envvar; the parser's unified parseinterp()
branches on it to emit tostring(getenv(NAME)).
2026-03-18 08:35:46 +00:00
Cormac Shannon
f88b17959f Hide shell functions from _G using upvalues on the main chunk
Store __command, __interactive, __getenv, __setenv as upvalues
populated by lua_load() from the registry, keeping them invisible
to user code while accessible to the parser's codegen.
2026-03-12 22:46:56 +00:00
Cormac Shannon
a43fd10e64 Implement shell globbing, tilde expansion, and brace expansion (issues #13, #18)
Unquoted tokens are now expanded through a tilde → brace → glob pipeline
in parse_argv. Quoted tokens (single, double, or backslash) suppress all
expansion. Uses glob(3) with GLOB_NOCHECK for wildcard matching and manual
implementations for tilde (~→$HOME) and brace ({a,b,c}) expansion.
2026-03-10 21:31:55 +00:00
Cormac Shannon
c96fae90c0 Fix nested commands in interactive mode triggering prompt2 (issue #19)
Save and restore cmd_mode across interpolation parsing so that
luaX_readcommandcont resumes in the correct mode after a nested
backtick command inside ${...}.
2026-03-05 00:13:34 +00:00
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
Cormac Shannon
4cc352cbec Implement shell builtins: cd, exec, umask (issue #15)
Add builtin dispatch in lcmd.c that checks __builtins table before
fork(), so cd/exec/umask operate on the shell process itself.
2026-03-04 19:20:42 +00:00
Cormac Shannon
e8756d5d78 Implement programmable prompt (issue #09)
Replace static _PROMPT/_PROMPT2 with dynamic __prompt(exitcode)/__prompt2(exitcode)
functions. Fallback chain: __prompt() → _PROMPT → "> ". Install a default __prompt
that shows the current directory with ~ abbreviation. Track last exit code from the
REPL loop and pass it to the prompt function.
2026-03-03 23:19:09 +00:00
Cormac Shannon
bbc0f24009 Implement startup configuration file support (issue #08)
Load ~/.config/lush/config and config.d/*.lua at REPL startup,
respecting XDG_CONFIG_HOME. Suppressed by -E flag.
2026-03-03 22:59:51 +00:00
Cormac Shannon
db858b3f68 Implement prefix-based interactive commands via ! (issue #14)
Add !command syntax that runs commands with inherited terminal (no
capture). The lexer treats ! as a statement-starting token, reading
to end-of-line with the same interpolation/escape/pipe support as
backtick commands. The C function sets _ = {code=N, stdout="", stderr=""}.
2026-03-02 22:06:29 +00:00
Cormac Shannon
d0181e685d Implement piping between commands in backtick syntax (issue #06)
Add split_pipeline() to split command strings on unquoted | and
exec_pipeline() to fork N children connected by inter-stage pipes.
Only the last stage's stdout/stderr are captured; middle stages'
stderr is inherited. Exit code comes from the last stage.
2026-03-01 22:17:30 +00:00
Cormac Shannon
41b2095ed9 Rewrite issue #10 for scripts+REPL, add issue #12, add interactive command tests
Redesign issue #10: bare-word commands now work in both scripts and
the REPL via a parser-level heuristic (identifier + non-exception-list
token → shell command). Add runtime fallback for string-arg syntax
(echo "hello"), double-dash flag handling, and classification examples.

Add issue #12 for path-based command execution (./script, /bin/ls, ~/bin/deploy).

Add testes/lush/commands-interactive.lua as a design playground covering
result table structure, exit codes, commands inside Lua blocks, _ behaviour,
runtime fallback, Lua variable shadowing, and interleaved Lua/shell.
2026-03-01 19:35:09 +00:00
Cormac Shannon
27f16b126d Add lush feature tests and fix /dev/full test for macOS
Add test suite under testes/lush/ covering backtick commands, argv
parsing, ${} interpolation, and $NAME environment variables. Wire
them into testes/all.lua so they run with the full Lua 5.5 suite.

Skip /dev/full test in files.lua when the device doesn't exist
(macOS has no /dev/full).
2026-02-28 19:07:00 +00:00