Skip to content

Commit dae77ce

Browse files
authored
Merge pull request #76 from TruFoundation/parser-executer-v2
- Extend parser AST/token support - Implement pipe/redirect execution - Add parser and executor tests - Upgrade docs and integration notes
2 parents ad52ce2 + 6df1e11 commit dae77ce

345 files changed

Lines changed: 695 additions & 42 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
# 🐄 TruShell
2-
A Productivity Shell for Task Tracking and Time Management
3-
42
**TruShell** is an interactive shell environment designed to integrate task tracking and time management tools seamlessly with traditional terminal commands. Built in Rust with a custom expression parser, TruShell extends the Unix philosophy by providing a unified interface where productivity features and system commands coexist naturally.
53

64
---
@@ -32,8 +30,9 @@ TruShell is not a replacement shell but rather a **productivity layer** that bri
3230
### Key Features
3331

3432
- **Hybrid Parsing**: Intelligently distinguishes between shell commands and custom expressions
35-
- **Expression Evaluation**: Supports arithmetic, comparisons, variables, and pipelines
33+
- **Expression Evaluation**: Supports arithmetic, comparisons, variables, pipelines, and redirects
3634
- **Pipeline Support**: Chain operations together using the pipe operator (`|`)
35+
- **Redirect Support**: Handle command redirection with `>`, `>>`, `<`, and `&>` for both standalone commands and pipeline stages
3736
- **Task Integration**: Foundation for task tracking and time management (future expansion)
3837
- **Graceful Fallback**: Executes as system commands if parsing fails
3938

@@ -185,6 +184,18 @@ Chain operations together using `|`:
185184
trushell ❯ ls() | filter { $it.size > 1mb }
186185
```
187186

187+
#### Redirects
188+
189+
Redirect command input/output and combine streams:
190+
191+
```
192+
trushell ❯ echo hello > out.txt
193+
trushell ❯ echo append >> out.txt
194+
trushell ❯ cat < in.txt
195+
trushell ❯ echo hello | cat > out.txt
196+
trushell ❯ echo error &> error.log
197+
```
198+
188199
---
189200

190201
## LANGUAGE FEATURES
@@ -355,6 +366,7 @@ pub enum ASTNode {
355366
Let { name: String, value: Box<ASTNode> },
356367
Pipeline { stages: Vec<Box<ASTNode>> },
357368
Command { name: String, args: Vec<ASTNode> },
369+
Redirect { source: Box<ASTNode>, fd: u8, mode: RedirectMode, target: RedirectTarget, merge_stderr: bool },
358370
Block { body: Vec<ASTNode> },
359371
BinaryOp { left: Box<ASTNode>, op: BinaryOperator, right: Box<ASTNode> },
360372
Variable(String),
@@ -614,6 +626,18 @@ Err(err) => {
614626

615627
**Result**: Most Unix commands work transparently even if parsing fails.
616628

629+
### Redirect and Pipeline Execution
630+
631+
TruShell now supports shell-style redirection for parsed commands, including standalone redirects and redirects on pipeline stages. The execution engine resolves redirect AST nodes before spawning processes and correctly wires command stdin/stdout for pipes:
632+
633+
- `cmd > file` writes stdout to a file
634+
- `cmd >> file` appends stdout to a file
635+
- `cmd < file` reads stdin from a file
636+
- `cmd &> file` redirects stderr to the same target file
637+
- `cmd | other > file` pipes data into a redirected final stage
638+
639+
This integration keeps parsed AST behavior aligned with traditional shell semantics while preserving the existing fallback execution model.
640+
617641
### Process Management
618642

619643
Commands are executed with inherited I/O streams:

src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
mod parser;
22

3+
use std::fs::OpenOptions;
34
use std::io::{self, Write};
4-
use std::process::{Command, Stdio};
5+
use std::process::{Child, Command, ExitStatus, Stdio};
56

67
fn main() {
78
println!("Welcome to TruShell Native Engine");

0 commit comments

Comments
 (0)