Enhanced directory tree printer with Git integration and ls-like features.
TreeLS combines the functionality of the classic tree
command with Git status awareness, providing color-coded file status indicators and powerful filtering options. Perfect for developers who want to quickly visualize project structure and Git state.
I've written a medium article for you to take a deepdive into my thought process.
I Built TreeLS: A Git-Aware Directory Tree Tool β And You Should Try It
- π³ Beautiful Tree Display: Rich, colorized directory tree output
- π₯ Git Integration: Color-coded files based on Git status (PyCharm-style)
- π― Smart Filtering: Show only specific types of files (staged, modified, untracked, etc.)
- π .gitignore Aware: Automatically respects .gitignore patterns
- β‘ Fast & Lightweight: Minimal dependencies, maximum performance
- π‘οΈ Safe by Default: Hides .git folder and respects ignore patterns
Color | Status | Description |
---|---|---|
π΄ Red | Untracked | Files not in version control |
π’ Green | Staged | Files staged for commit |
π‘ Yellow | Modified | Files modified but not staged |
β« Dark Grey | Deleted | Files marked for deletion |
Default | Committed | Clean, committed files |
π Grey | Non-Git | Files in non-Git directories |
pip install treels-cli
Or install from source:
git clone <repository-url>
cd treels
pip install -e .
# Basic tree view
treels
# Show all files including hidden ones
treels -a
# Show Git status legend
treels --git-status
# Show only modified files
treels --only-modified
Basic tree view:
/home/user/my-project (git)
βββ README.md
βββ src/
β βββ main.py
β βββ utils.py
β βββ config.json
βββ tests/
β βββ test_main.py
β βββ test_utils.py
βββ requirements.txt
With Git status colors (when in a Git repository):
/home/user/my-project (git)
βββ README.md # Default (committed)
βββ src/
β βββ main.py # Yellow (modified)
β βββ utils.py # Green (staged)
β βββ config.json # Default (committed)
βββ tests/
β βββ test_main.py # Red (untracked)
β βββ test_utils.py # Default (committed)
βββ requirements.txt # Default (committed)
βββ new_feature.py # Red (untracked)
Filtered view (--only-modified --only-untracked):
/home/user/my-project (git)
βββ src/
β βββ main.py # Yellow (modified)
βββ tests/
β βββ test_main.py # Red (untracked)
βββ new_feature.py # Red (untracked)
Note: In actual terminal output, the files appear in the colors described in the comments. The examples above show the structure with status indicators for clarity.
# Current directory tree
treels
# Specific directory
treels /path/to/project
# Show hidden files (but not .git folder)
treels -a
# Show everything including .git folder
treels -a --show-git
Example: Basic tree in a Python project
/home/user/my-app
βββ app.py
βββ requirements.txt
βββ src/
β βββ __init__.py
β βββ models.py
β βββ views.py
βββ tests/
β βββ test_app.py
βββ docs/
βββ README.md
Example: With hidden files (-a)
/home/user/my-app
βββ .env
βββ .gitignore
βββ app.py
βββ requirements.txt
βββ src/
β βββ .cache/
β βββ __init__.py
β βββ models.py
β βββ views.py
βββ tests/
β βββ test_app.py
βββ docs/
βββ README.md
# Show only files with changes (any status)
treels --git-uncommitted-only
# Show only committed files (clean)
treels --git-exclude-uncommitted
# Show only staged files (ready for commit)
treels --only-staged
# Show only modified files (need staging)
treels --only-modified
# Show only untracked files (new files)
treels --only-untracked
# Show only deleted files
treels --only-deleted
# Combine filters: show staged OR modified files
treels --only-staged --only-modified
# Show files ready for review (staged + modified)
treels --only-staged --only-modified --git-status
Example: Only modified files (--only-modified)
/home/user/my-app (git)
βββ src/
β βββ models.py # Yellow (modified)
β βββ views.py # Yellow (modified)
βββ app.py # Yellow (modified)
Example: Only untracked files (--only-untracked)
/home/user/my-app (git)
βββ temp_script.py # Red (untracked)
βββ src/
β βββ new_feature.py # Red (untracked)
βββ docs/
βββ draft.md # Red (untracked)
Example: Combined filters (--only-staged --only-modified)
/home/user/my-app (git)
βββ README.md # Green (staged)
βββ src/
β βββ models.py # Yellow (modified)
β βββ views.py # Yellow (modified)
β βββ config.py # Green (staged)
βββ app.py # Yellow (modified)
Example: With Git status legend (--git-status)
/home/user/my-app (git)
βββ README.md # Green (staged)
βββ src/
β βββ models.py # Yellow (modified)
β βββ new_feature.py # Red (untracked)
βββ app.py # Default (committed)
Git Status: Red=Untracked Green=Staged Yellow=Modified Dark Grey=Deleted Default=Committed Grey=Non-Git
Filter Options: --only-staged --only-modified --only-untracked --only-deleted
(Combine multiple filters with OR logic)
# Limit depth
treels --max-depth 2
# Custom ignore patterns
treels --ignore "node_modules,dist,build"
# Show .gitignore'd files
treels --show-ignored
# Highlight directories in blue
treels --highlight-dirs
# Full status with legend
treels --git-status --only-modified --only-untracked
Example: Max depth limit (--max-depth 2)
/home/user/my-app
βββ app.py
βββ requirements.txt
βββ src/
β βββ models.py
β βββ views.py
βββ tests/
β βββ test_app.py
βββ docs/
βββ README.md
Example: Custom ignore (--ignore "tests,docs")
/home/user/my-app
βββ app.py
βββ requirements.txt
βββ src/
βββ models.py
βββ views.py
Example: Highlight directories (--highlight-dirs)
/home/user/my-app
βββ app.py
βββ requirements.txt
βββ src/ # Bold blue
β βββ models.py
β βββ views.py
βββ tests/ # Bold blue
βββ test_app.py
# Show Git status codes before filenames (like git status --short)
treels --show-status-codes
# Combine with colors and legend for full information
treels --show-status-codes --git-status
# Perfect for terminals without color support
treels --show-status-codes --only-modified
Example: With Git status codes (--show-status-codes)
/home/user/my-app (git)
βββ README.md
βββ src/
β βββ A api.py # Green (staged)
β βββ M utils.py # Yellow (modified)
β βββ ?? new_feature.py # Red (untracked)
βββ M app.py # Yellow (modified)
Git Status: Red=Untracked Green=Staged Yellow=Modified
Status Codes: ?? = Untracked, A = Staged, M = Modified, D = Deleted
Benefits of Status Codes:
- Accessibility: Works in terminals without color support
- CI/CD Friendly: Status codes visible in automated logs
- Familiar: Uses exact
git status --short
format - Redundant Info: Both visual colors AND text codes
Option | Description |
---|---|
path |
Root directory (default: current directory) |
-a, --all |
Show hidden files and directories |
--show-ignored |
Show files ignored by .gitignore |
--show-git |
Show .git folder (hidden by default) |
--ignore DIRS |
Comma-separated list of directories to ignore |
--max-depth N |
Maximum depth to traverse |
--git-status |
Show Git status legend |
--highlight-dirs |
Highlight directories in blue |
--show-status-codes |
Show Git status codes before filenames |
Option | Description |
---|---|
--git-uncommitted-only |
Show only files with any changes |
--git-exclude-uncommitted |
Show only committed (clean) files |
--only-staged |
Show only staged files (green) |
--only-modified |
Show only modified files (yellow) |
--only-untracked |
Show only untracked files (red) |
--only-deleted |
Show only deleted files (dark grey) |
Note: The --only-*
filters can be combined with OR logic. For example, --only-staged --only-modified
shows files that are either staged OR modified.
# See what's staged for commit
treels --only-staged
# See what still needs staging
treels --only-modified --only-untracked
# Full pre-commit overview
treels --git-status --only-staged --only-modified --only-untracked
Example: Pre-commit review
$ treels --only-staged
/home/user/my-app (git)
βββ README.md # Green (staged)
βββ src/
βββ config.py # Green (staged)
$ treels --only-modified --only-untracked
/home/user/my-app (git)
βββ src/
β βββ models.py # Yellow (modified)
β βββ new_feature.py # Red (untracked)
βββ temp_notes.txt # Red (untracked)
# Show all changed files
treels --git-uncommitted-only
# Focus on specific changes
treels --only-modified --git-status
Example: Code review overview
$ treels --git-uncommitted-only
/home/user/my-app (git)
βββ README.md # Green (staged)
βββ src/
β βββ models.py # Yellow (modified)
β βββ new_feature.py # Red (untracked)
β βββ config.py # Green (staged)
βββ temp_notes.txt # Red (untracked)
# Clean project view (hide temp files, show structure)
treels --max-depth 3
# Show everything for debugging
treels -a --show-ignored --show-git
Example: Clean project structure
$ treels --max-depth 3
/home/user/my-app
βββ README.md
βββ requirements.txt
βββ src/
β βββ __init__.py
β βββ models/
β β βββ user.py
β β βββ product.py
β βββ views/
β βββ api.py
β βββ web.py
βββ tests/
β βββ unit/
β β βββ test_models.py
β β βββ test_views.py
β βββ integration/
β βββ test_api.py
βββ docs/
βββ API.md
βββ DEPLOYMENT.md
# Hide build artifacts and dependencies
treels --ignore "node_modules,dist,build,target,.next"
# Focus on source code changes
treels --only-modified --max-depth 2
Example: Large project with filtering
$ treels --ignore "node_modules,dist" --max-depth 2
/home/user/large-project
βββ package.json
βββ src/
β βββ components/
β βββ pages/
β βββ styles/
β βββ utils/
βββ public/
β βββ images/
β βββ icons/
βββ tests/
βββ unit/
βββ e2e/
pipenv install --dev
# Activate virtual environment
pipenv shell
# Run tests
pipenv run test
# Format code
pipenv run format
# Lint code
pipenv run lint
# Build package
pipenv run build
# Run all tests
pytest tests/
# Run with coverage
pytest tests/ --cov=treels
# Run specific test
pytest tests/test_treels.py::TestGitRepository::test_gitignore_parsing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Make your changes
- Add tests for new functionality
- Run the test suite (
pipenv run test
) - Format your code (
pipenv run format
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Inspired by the classic
tree
command - Git status colors based on PyCharm's color scheme
- Built with Rich for beautiful terminal output
Please use the GitHub Issues page to report bugs or request features. When reporting bugs, please include:
- Your operating system and Python version
- The command you ran
- Expected vs actual behavior
- Sample directory structure (if relevant)