A lightweight shell script that generates beautiful ASCII directory tree structures for your projects. Works on Linux and macOS without any dependencies - just pure bash!
- 🌳 Hierarchical .gitignore parsing - Finds and applies all .gitignore files like git does
- 🎯 Zero dependencies - Pure bash, no Node.js or Python required
- 📁 Flexible filtering - Include/exclude files using regex patterns
- 📊 Directory depth control - Limit tree depth
- 🛠 Debug mode - See pattern matching details
- 💾 Custom output - Save anywhere with custom naming
- 🚀 Dry run mode - Preview before saving
# Download the script
curl -O https://raw.githubusercontent.com/MaciejPopenda/ascii-tree-generator-bash-linux/main/ascii-tree-generator.sh
# Make it executable
chmod +x ascii-tree-generator.sh
# Optionally, move to your PATH
sudo mv ascii-tree-generator.sh /usr/local/bin/ascii-tree-generator- Clone this repository:
git clone https://github.com/MaciejPopenda/ascii-tree-generator-bash-linux.git
cd ascii-tree-generator-bash-linux- Make the script executable:
chmod +x ascii-tree-generator.sh- Run it:
./ascii-tree-generator.shGenerate a tree for your current project:
./ascii-tree-generator.shThis creates project-ascii-tree.txt:
my-project/
├── src/
│   ├── components/
│   │   ├── Header.js
│   │   └── Footer.js
│   └── index.js
├── package.json
└── README.md
# Generate tree with default settings
./ascii-tree-generator.sh
# Preview without creating file
./ascii-tree-generator.sh --dry-run
# Include all files (ignore .gitignore)
./ascii-tree-generator.sh --all# Only show JavaScript files
./ascii-tree-generator.sh --include-pattern '\.js$'
# Exclude tests
./ascii-tree-generator.sh --exclude-pattern 'test|spec'
# Show only source code
./ascii-tree-generator.sh --include-pattern 'src/'# Limit depth and save to docs/
./ascii-tree-generator.sh --max-depth 3 --output-path ./docs/
# Debug your patterns
./ascii-tree-generator.sh --debug --include-pattern '\.js$'
# Custom output with filters
./ascii-tree-generator.sh \
  --include-pattern '\.(md|txt)$' \
  --output-name "docs-structure.txt"| Option | Description | Example | 
|---|---|---|
| --all | Include all files (ignore .gitignore) | --all | 
| --except-dir | Additional directories to ignore | --except-dir "build,dist" | 
| --except-file | Additional files to ignore | --except-file "*.log,*.tmp" | 
| --output-name | Custom output filename | --output-name "tree.txt" | 
| --output-path | Custom output directory | --output-path "./docs/" | 
| --dry-run | Preview without creating file | --dry-run | 
| --debug | Show debug information | --debug | 
| --max-depth | Maximum directory depth | --max-depth 3 | 
| --include-pattern | Regex to include files | --include-pattern '\.js$' | 
| --exclude-pattern | Regex to exclude files/dirs | --exclude-pattern 'test' | 
| --help, -h | Show help message | --help | 
- ✅ Linux - Works out of the box
- ✅ macOS - Works out of the box
- ⚠️ Windows - Requires WSL, Git Bash, or Cygwin
On Windows, you have these options:
- WSL (Windows Subsystem for Linux) - Recommended
- Git Bash - Comes with Git for Windows
- Cygwin - Unix-like environment for Windows
- Use the Node.js version - See ascii-tree-generator
Add to .git/hooks/post-commit:
#!/bin/bash
cd "$(git rev-parse --show-toplevel)"
./ascii-tree-generator.shMake it executable:
chmod +x .git/hooks/post-commitUses grep Extended Regular Expressions (ERE):
# Single file type
--include-pattern '\.js$'
# Multiple file types
--include-pattern '\.(js|ts|json)$'
# Files containing 'component'
--include-pattern 'component'
# Exclude tests and build files
--exclude-pattern 'test|build|dist'MIT License - See LICENSE file for details
Contributions welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
Found a bug? Please open an issue
- ascii-tree-generator (Node.js version) - Original Node.js implementation
Made with ❤️ for developers who love simplicity