You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add printf, read, break, continue, command, function and type builtins (#280)
* Harden shell: eliminate panics, implement all file test operators, fix path resolution
- Replace panic!() in parser (for loop wordlist) and types (arithmetic) with
proper error handling/fallback behavior
- Replace unreachable!() in parser (and_or lists, boolean operators), execute
(assignment operators), and main (script/command dispatch) with descriptive errors
- Implement all 14 previously unimplemented file test operators: -b (block special),
-c (char special), -g (setgid), -k (sticky bit), -p (named pipe), -s (size > 0),
-t (terminal fd), -u (setuid), -G (owned by egid), -N (modified since read),
-O (owned by euid), -S (socket), -R (nameref), and None (implicit -n)
- Add -e (file exists) and -t (terminal fd) to grammar and parser
- Fix file test path resolution to use shell CWD instead of process CWD
- Fix critical unwrap() calls in main.rs (current_dir), execute.rs (parse result),
uname.rs, touch.rs (DST-ambiguous datetimes), set.rs, and mod.rs (clear command)
- Add comprehensive test suite for file test operators (3 new test functions)
* Add missing bash builtins: break, continue, :, printf, read, command, type
Implement 7 new shell builtins for improved bash compatibility:
- break/continue: Loop control flow via sentinel exit codes (-100/-101)
that propagate through ExecuteResult::Exit and are caught by while/for loops
- : (colon): No-op command that always returns 0
- printf: Format string support with %s, %d, %o, %x, %f, %c, %b specifiers,
width/precision/flags, and standard escape sequences
- read: Read input with -r (raw) and -p (prompt) flags, field splitting,
default REPLY variable
- command: Run commands bypassing aliases, -v flag for path lookup
- type: Describe how a command name resolves (alias, builtin, or PATH)
All builtins include comprehensive tests.
* Add bash builtins: eval, source, shift, local, return, trap
Implement 6 more shell builtins for improved bash compatibility:
- eval: Parse and execute string arguments as shell commands
- source/.: Fix to use context pipes instead of real stdout/stderr,
enabling proper pipe capture in tests and subshells. Read file,
parse, and execute in current shell context with env change propagation
- shift: Shift positional parameters ($1, $2, ...) left by N
- local: Declare shell-scoped variables (foundation for future
function support)
- return: Exit from sourced scripts with specified exit code via
ExecuteResult::Exit propagation
- trap: Basic signal handling with -l (list signals), -p (print traps),
and handler registration acceptance for compatibility
All builtins include comprehensive tests. Total: 46 tests passing.
https://claude.ai/code/session_01GTXgqqxHbE7ACysQDZ9cLU
* Implement shell function definitions, positional parameters, and brace groups
- Add function_definition parsing (foo() { ... }) with FunctionDefinition AST node
- Store functions in ShellState and execute via execute_shell_function
- Support positional parameters ($1-$N, $#, $@, $*) with save/restore across calls
- Fix grammar: UNQUOTED_ESCAPE_CHAR now excludes SPECIAL_PARAM so $1/$2/etc parse correctly
- Fix RETURN_EXIT_CODE sentinel handling at top level and in function scope
- Sync last_command_exit_code with shell var "?" for proper $? expansion
- Add brace group compound command support
- Add comprehensive tests for functions, positional params, return values, nested calls
* fix lint / fmt
* Add e2e test-data files for functions and builtins
- functions.sh: tests for function definitions, positional parameters
($1-$N, $#, $@), nested calls, variable scoping, and function overriding
- builtins.sh: tests for eval, shift, local, and brace groups
0 commit comments