ChELL now supports Unix-style piping to chain chell commands with local system tools.
The piping feature allows you to:
- Execute a chell command and pipe its output to local tools
- Chain multiple pipes for complex data processing
- Handle both text and binary data
chell_command | local_tool [args] | another_tool [args]- Parse: ChELL parses the command line and splits it on pipe operators (
|) - Execute: The first segment is executed as a chell builtin command
- Capture: Output from the chell command is captured in a buffer
- Pipe: The captured output is piped through each subsequent local tool
- Output: Final result is displayed to the user
# Pipe a file to jq for JSON formatting
cat data.json | jq
# Pipe to grep to filter results
ls -l | grep .txt# Chain multiple pipes
cat file.json | jq '.data' | wc -l
# Complex filtering
files | grep complete | sort# Pipe binary files (e.g., images)
cat image.jpg | imagemagick convert - output.pngThe pipes_parse() function intelligently splits commands on pipe operators while respecting quoted strings:
- Handles single quotes (
') - Handles double quotes (
") - Pipe characters inside quotes are NOT treated as operators
Example:
cat "file | with | pipes.txt" | grep test
# ^ This pipe inside quotes is preserved
# ^ This pipe is the operatorThe output_capture() function temporarily redirects console.log and console.error to capture all output from builtin commands into a buffer. This ensures:
- All command output is captured
- Both stdout and stderr are collected
- Original console methods are restored after execution
The pipe_execute() function:
- Executes the first command using
chellCommand_executeAndCapture() - Spawns each subsequent command as a child process
- Pipes data from one process to the next
- Uses Node.js
spawnwith proper stdio configuration - Handles errors gracefully with descriptive messages
The implementation uses Node.js Buffer throughout the pipe chain to support both text and binary data:
- Output is captured as
Buffer - Data is piped through processes as binary streams
- Final output is written to stdout preserving binary integrity
-
ChELL commands only in first position: Only the first segment can be a chell builtin command. Subsequent segments must be local system tools.
# ✓ Correct cat file.txt | grep test # ✗ Incorrect echo test | cat /some/chell/path
-
Help flags: The
--helpflag in piped commands is not processed separately. It will be passed as an argument to the command. -
Interactive commands: Commands requiring user input in the middle of a pipe chain may not work as expected.
If any command in the pipe chain fails:
- An error message is displayed showing which command failed
- The pipe chain execution stops
- No partial output is displayed
Example error:
cat file.json | invalid_command
# Output: Pipe error: Command 'invalid_command' exited with code 127- File:
src/chell.ts - Functions:
pipes_parse(line: string): string[]- Parses command line for pipesoutput_capture(fn: () => Promise<void>): Promise<{text: string; buffer: Buffer}>- Captures console outputchellCommand_executeAndCapture(commandLine: string): Promise<{text: string; buffer: Buffer}>- Executes chell command with output capturepipe_execute(segments: string[]): Promise<void>- Executes pipe chaincommand_handle(line: string): Promise<void>- Modified to detect and handle pipes
The piping feature is integrated into the main command handling flow:
command_handle()receives user input- Checks for pipe operators using
pipes_parse() - If pipes detected, delegates to
pipe_execute() - Otherwise, executes as normal builtin command
Basic tests are included in tests/pipes.test.ts. To manually test:
# Start chell
npm start
# In chell, try:
pwd | cat
ls | wc -l
context | grep URLPotential improvements:
- Support for output redirection (
>,>>) - Input redirection (
<) - Background processes (
&) - Process substitution (
<(),>()) - Pipe to multiple chell commands in sequence