gsh is a lightweight, custom shell implemented from scratch in Go. It provides a simple REPL (Read-Eval-Print Loop) to execute commands, handle input/output, and spawn processes, aiming to give developers a clear understanding of shell internals while offering a functional CLI environment.
- Custom Command Parser: Built-in tokenizer and parser for command processing
- Built-in Commands: Essential shell commands implemented natively
echo- Display textpwd- Print working directorycd- Change directoryls- List directory contentsclear- Clear the terminal screenwhoami- Display current userhelp- Show available commandsexit- Exit the shell
- External Command Execution: Execute system commands from
/bin/ - Configurable Environment: Customizable prompt, theme, and color mode
- Command History: Track command history throughout the session
- Environment Variables: Manage shell environment variables
- Color Support: Optional colored output for enhanced user experience
- Go 1.25.1 or higher
- Linux/Unix-based operating system
# Clone the repository
git clone <repository-url>
cd gsh
# Build the project
go build -o bin/gsh cmd/gsh/main.go
# Run the shell
./bin/gshgo install cmd/gsh/main.goStart the shell by running:
./bin/gshYou'll be greeted with a prompt that shows your current directory:
/home/user/workspace
gsh>
gsh/
├── cmd/
│ └── gsh/
│ └── main.go # Entry point
├── internal/
│ ├── builtins/ # Built-in command implementations
│ │ ├── builtins.go # Command registry
│ │ ├── cd.go
│ │ ├── clear.go
│ │ ├── echo.go
│ │ ├── exit.go
│ │ ├── help.go
│ │ ├── ls.go
│ │ ├── pwd.go
│ │ └── whoami.go
│ ├── command/ # Command parsing
│ │ ├── command.go
│ │ └── parser.go
│ ├── config/ # Configuration management
│ │ ├── config.go
│ │ └── deafult.go
│ └── shell/ # Core shell implementation
│ ├── deafult.go
│ ├── repl.go # REPL loop
│ └── shell.go # Shell structure
├── plugins/ # Plugin system (extensible)
├── bin/ # Compiled binaries
├── go.mod # Go module definition
└── README.md
The shell can be configured through the Config structure:
type Config struct {
Prompt string // Custom prompt string
Theme string // Color theme
ColorMode bool // Enable/disable colors
HistoryFile string // Command history file path
}Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/Feature) - Commit your changes (
git commit -m 'Add some Feature') - Push to the branch (
git push origin feature/Feature) - Open a Pull Request
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
- Plugin system implementation
- Command piping support (
|) - Input/Output redirection (
>,<,>>) - Background job execution (
&) - Tab completion
- Advanced history management with search
- Configuration file support
- Alias support
- Scripting capabilities
- Inspired by traditional Unix shells (bash, zsh, sh)
- Built as an educational project to understand shell internals