A lightweight, fast implementation of the popular tree
command, written in Zig for macOS systems.
Why install tree from homebrew when you can rewrite it from scratch?
- Display directory structures in a tree-like format
- Custom sorting logic:
- Hidden files first (when enabled)
- Uppercase files/directories first
- Directories before files
- Alphanumeric sorting
- Command-line flags to customize behavior
- Memory-safe implementation using Zig
- Zig language (0.14.0 or later recommended)
# Clone the repository
git clone https://github.com/dbrtly/tree.git
cd tree
# Build the executable
zig build
# test the code
zig test tree.zig
# Optional: Move to a directory in your PATH
cp tree /usr/local/bin/
Basic usage:
# Show tree structure of current directory
./tree
# Show tree structure of specified directory
./tree /path/to/directory
Flag | Long Form | Description |
---|---|---|
-a |
--all |
Show hidden files (starting with . ) |
-L n |
--max-depth n |
Limit directory recursion to n levels deep |
|
Show all files including hidden ones:
./tree -a
Limit directory depth to 2 levels:
./tree -L 2
Combine options:
./tree -a -L 3 ~/Documents
tree
├── README.md
├── installer.sh
├── tree
├── tree.o
└── tree.zig
$ tree --all
tree
├── .zig-cache
│ └── tmp
├── .gitattributes
├── .gitignore
├── README.md
├── installer.sh
├── tree
├── tree.o
└── tree.zig
- Optimized for macOS
- Custom sorting algorithm prioritizing:
- Hidden files (when shown)
- Uppercase items
- Directories
- Alphanumeric order
MIT License
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request