gash is a small interactive Unix-like shell written in Go. It supports builtins, external commands, pipelines, redirection, tab completion, command history, and background jobs.
Install the binary with Go:
go install github.com/deltron-fr/gash/cmd/gash@latestOr run it directly from the repository:
go run ./cmd/gashStart the shell:
gashBasic examples:
pwd
cd ~/projects
echo "hello"
ls -la | grep go
go test ./... > test.log
sleep 30 &
jobsgash is intentionally small. These are not implemented yet:
- A shell scripting language
- Command substitution such as
$(...) - Job control signals such as
fg,bg,SIGTSTP, andSIGCONThandling
Implementation notes live in docs/, including an overview of the lexer, parser, executor, and readline flow.
gash currently includes these builtins:
| Command | Description |
|---|---|
cd |
Change the current working directory |
pwd |
Print the current working directory |
echo |
Print text |
exit |
Exit the shell |
type |
Show whether a command is a builtin or an executable on PATH |
history |
Print history or read/write history files |
jobs |
Show background jobs tracked by the shell |
complete |
Register, inspect, or remove completion scripts |
Commands that are not builtins are resolved through PATH and executed as child processes.
Use | to connect commands:
cat go.mod | grep moduleSupported redirection operators:
| Operator | Effect |
|---|---|
> / 1> |
Redirect stdout |
>> / 1>> |
Append stdout |
2> |
Redirect stderr |
2>> |
Append stderr |
Examples:
go test ./... > out.log
go test ./... 2> err.log
go test ./... >> out.logAppend & to run a command in the background:
sleep 30 &
jobsgash supports:
- Single quotes:
'literal text' - Double quotes:
"quoted text" - Backslash escaping outside quotes
- Escaping
"and\inside double quotes
Examples:
echo 'hello world'
echo "hello world"
echo hello\ worldTab completion supports:
- Builtin commands
- Executables found on
PATH - Files and directories in the current working directory
- Custom completion scripts registered with
complete -C
If HISTFILE is set, gash loads history from that file on startup.
The history builtin supports:
| Command | Description |
|---|---|
history |
Print all in-memory history entries |
history N |
Print the last N entries |
history -r <file> |
Read entries from a file into history |
history -w <file> |
Write the current history to a file |
history -a <file> |
Append the current session history to a file |
Example:
export HISTFILE="$HOME/.gash_history"
gashThe complete builtin can register an executable script as a completer for a command:
complete -C ./scripts/my-completer git
complete -p git
complete -r gitThe completer is executed with:
- argv:
<command-name> <current-token> <previous-token> - env:
COMP_LINEandCOMP_POINT
Each completion candidate should be written on its own line.
Run locally:
go run ./cmd/gashRun tests:
go test ./...