A command-line tool for visualizing directory structures
Project description
Recursivist
A beautiful command-line tool for visualizing directory structures with rich formatting, color-coding, and multiple export options.
Features
- ๐จ Colorful Visualization: Each file type is assigned a unique color for easy identification
- ๐ณ Tree Structure: Displays your directories in an intuitive, hierarchical tree format
- ๐ Smart Filtering: Easily exclude directories and file extensions you don't want to see
- ๐งฉ Gitignore Support: Automatically respects your
.gitignorepatterns - ๐ Powerful Pattern Matching: Use glob and regex patterns to precisely include or exclude files
- ๐ Directory Comparison: Compare two directory structures side by side with highlighted differences
- ๐ Multiple Export Formats: Export to TXT, JSON, HTML, Markdown, and React components
- ๐ Depth Control: Limit the display depth to focus on higher-level structure
- ๐ Full Path Display: Option to show full paths instead of just filenames
- ๐ Simple Interface: Intuitive command-line interface with smart defaults
Installation
From PyPI
pip install recursivist
From Source
git clone https://github.com/ArmaanjeetSandhu/recursivist.git
cd recursivist
pip install .
Usage
Basic Usage
Just run the command in any directory:
recursivist visualize
This will show a colorful tree of the current directory structure in your terminal.
Command Overview
| Command | Description |
|---|---|
visualize |
Display directory structures in the terminal |
export |
Export directory structures to various formats |
compare |
Compare two directory structures side by side |
completion |
Generate shell completion scripts |
version |
Show the current version |
Advanced Options
Visualize Command
# Visualize a specific directory
recursivist visualize /path/to/directory
# Exclude specific directories
recursivist visualize \
--exclude node_modules .git venv
# Exclude file extensions
recursivist visualize \
--exclude-ext .pyc .log .cache
# Use a gitignore-style file
recursivist visualize \
--ignore-file .gitignore
# Use glob patterns to exclude files
recursivist visualize \
--exclude-pattern "*.test.js" "*.spec.js"
# Use regex patterns for more precise control
recursivist visualize \
--exclude-pattern "^test_.*\.py$" ".*_test\.js$" \
--regex
# Include only specific patterns (overrides exclusions)
recursivist visualize \
--include-pattern "src/*" "*.md"
# Include with regex patterns
recursivist visualize \
--include-pattern "^src/.*\.jsx?$" "^docs/.*\.md$" \
--regex
# Limit directory depth
recursivist visualize \
--depth 3
# Show full file paths
recursivist visualize \
--full-path
# Enable verbose output
recursivist visualize \
--verbose
Export Command
# Export to various formats
recursivist export \
--format txt json html md jsx
# Export a specific directory to a specific output directory
recursivist export /path/to/directory \
--format md \
--output-dir ./exports
# Export as a React component
recursivist export \
--format jsx \
--output-dir ./components
# Custom filename prefix for exports
recursivist export \
--format json \
--prefix my-project
# Export with exclusions and pattern matching
recursivist export \
--exclude node_modules \
--exclude-ext .pyc \
--exclude-pattern "*.test.js"
# Export with depth limit and full paths
recursivist export \
--depth 2 \
--full-path
Compare Command
# Compare two directories
recursivist compare /path/to/dir1 /path/to/dir2
# Compare with pattern exclusions
recursivist compare dir1 dir2 \
--exclude-pattern "*.test.js" \
--regex
# Compare with depth limit
recursivist compare dir1 dir2 \
--depth 2
# Compare and export the comparison
recursivist compare dir1 dir2 \
--save \
--output-dir ./reports
# Compare with full paths
recursivist compare dir1 dir2 \
--full-path
# Compare with directory exclusions
recursivist compare dir1 dir2 \
--exclude node_modules .git
Other Commands
# View the current version
recursivist version
# Generate shell completion for different shells
recursivist completion bash > ~/.bash_completion.d/recursivist
recursivist completion zsh > ~/.zsh/completion/_recursivist
recursivist completion fish > ~/.config/fish/completions/recursivist.fish
recursivist completion powershell > recursivist.ps1
Command Options
visualize Command Options
| Option | Short | Description |
|---|---|---|
--exclude |
-e |
Directories to exclude (space-separated or multiple flags) |
--exclude-ext |
-x |
File extensions to exclude (space-separated or multiple flags) |
--exclude-pattern |
-p |
Patterns to exclude (glob by default, regex with --regex flag) |
--include-pattern |
-i |
Patterns to include (overrides exclusions) |
--regex |
-r |
Treat patterns as regex instead of glob patterns |
--ignore-file |
-g |
Ignore file to use (e.g., .gitignore) |
--depth |
-d |
Maximum depth to display (0 for unlimited) |
--full-path |
-l |
Show full paths instead of just filenames |
--verbose |
-v |
Enable verbose output |
export Command Options
| Option | Short | Description |
|---|---|---|
--format |
-f |
Export formats: txt, json, html, md, jsx |
--output-dir |
-o |
Output directory for exports |
--prefix |
-n |
Prefix for exported filenames |
--exclude |
-e |
Directories to exclude (space-separated or multiple flags) |
--exclude-ext |
-x |
File extensions to exclude (space-separated or multiple flags) |
--exclude-pattern |
-p |
Patterns to exclude (glob by default, regex with --regex flag) |
--include-pattern |
-i |
Patterns to include (overrides exclusions) |
--regex |
-r |
Treat patterns as regex instead of glob patterns |
--ignore-file |
-g |
Ignore file to use (e.g., .gitignore) |
--depth |
-d |
Maximum depth to display (0 for unlimited) |
--full-path |
-l |
Show full paths instead of just filenames |
--verbose |
-v |
Enable verbose output |
compare Command Options
| Option | Short | Description |
|---|---|---|
--exclude |
-e |
Directories to exclude (space-separated or multiple flags) |
--exclude-ext |
-x |
File extensions to exclude (space-separated or multiple flags) |
--exclude-pattern |
-p |
Patterns to exclude (glob by default, regex with --regex flag) |
--include-pattern |
-i |
Patterns to include (overrides exclusions) |
--regex |
-r |
Treat patterns as regex instead of glob patterns |
--ignore-file |
-g |
Ignore file to use (e.g., .gitignore) |
--depth |
-d |
Maximum depth to display (0 for unlimited) |
--full-path |
-l |
Show full paths instead of just filenames |
--save |
-f |
Save comparison result to HTML file |
--output-dir |
-o |
Output directory for exports |
--prefix |
-n |
Prefix for exported filenames |
--verbose |
-v |
Enable verbose output |
Examples
Basic Directory Visualization
recursivist visualize
This will produce output similar to:
๐ my-project
โโโ ๐ src
โ โโโ ๐ main.py
โ โโโ ๐ utils.py
โ โโโ ๐ tests
โ โโโ ๐ test_main.py
โ โโโ ๐ test_utils.py
โโโ ๐ README.md
โโโ ๐ requirements.txt
โโโ ๐ setup.py
Pattern Matching with Glob and Regex
Recursivist supports both glob patterns (default) and regular expressions for precise control over which files and directories to include or exclude.
Glob Pattern Examples
Glob patterns use wildcard characters like * to match multiple characters:
# Exclude all JavaScript test files
recursivist visualize \
--exclude-pattern "*.test.js" "*.spec.js"
# Include only source code and documentation
recursivist visualize \
--include-pattern "src/*" "docs/*.md"
Regex Pattern Examples
For more precise control, use the --regex flag to enable regular expressions:
# Exclude files starting with "test_" and ending with ".py"
recursivist visualize \
--exclude-pattern "^test_.*\.py$" \
--regex
# Include only React components in the src directory
recursivist visualize \
--include-pattern "^src/.*\.(jsx|tsx)$" \
--regex
Combining Include and Exclude Patterns
When you specify both include and exclude patterns, include patterns take precedence:
# Include all markdown files, but exclude those containing "draft"
recursivist visualize \
--include-pattern "*.md" \
--exclude-pattern "*draft*"
# With regex, include TypeScript files but exclude test files
recursivist visualize \
--include-pattern "^.*\.ts$" \
--exclude-pattern ".*\.test\.ts$" \
--regex
Directory Comparison
recursivist compare ~/project-v1 ~/project-v2
This will display two directory trees side by side with differences highlighted:
- Files and directories unique to each directory are highlighted
- A legend explains the color-coding
You can export the comparison to HTML:
recursivist compare ~/project-v1 ~/project-v2 \
--save \
--output-dir ./reports
Limiting Directory Depth
For large projects, it can be helpful to limit the display depth:
recursivist visualize \
--depth 2
This will show only the top two levels of the directory structure, with an indicator showing where the depth limit was reached.
Showing Full Paths
When you need to see the complete path for each file:
recursivist visualize \
--full-path
This will display the full path for each file rather than just the filename.
Export to Multiple Formats
recursivist export \
--format "txt md jsx" \
--output-dir ./docs
This exports the directory structure to text, markdown, and React component formats in the ./docs directory.
Exclude Unwanted Directories and Files
recursivist visualize \
--exclude node_modules .git \
--exclude-ext .pyc .log
This shows the directory tree while ignoring the node_modules and .git directories, as well as any .pyc and .log files.
Export Formats
Text (TXT)
A simple ASCII tree representation that can be viewed in any text editor.
JSON
A structured JSON format that can be easily parsed by other tools or scripts.
HTML
An HTML representation with styling that can be viewed in any web browser.
Markdown (MD)
A markdown representation that renders nicely on platforms like GitHub.
React Component (JSX)
An interactive React component with a collapsible tree view that can be integrated into your web applications. The component uses Tailwind CSS for styling and includes features like "Expand All" and "Collapse All" buttons.
recursivist export \
--format jsx \
--output-dir ./components
This creates a self-contained React component file that you can import directly into your React projects. To use it:
-
Copy the generated
.jsxfile to your React project's components directory -
Make sure you have the required dependencies:
npm install lucide-react -
Import and use the component in your application:
import DirectoryViewer from "./components/structure.jsx"; function App() { return ( <div className="App"> <DirectoryViewer /> </div> ); }
Note: The component uses Tailwind CSS for styling. If your project doesn't use Tailwind, you'll need to add it or modify the component to use your preferred styling solution.
Shell Completion
Recursivist supports shell completion for easier command entry. Generate completion scripts with:
# For Bash
recursivist completion bash > ~/.bash_completion.d/recursivist
# For Zsh
recursivist completion zsh > ~/.zsh/completion/_recursivist
# For Fish
recursivist completion fish > ~/.config/fish/completions/recursivist.fish
# For PowerShell
recursivist completion powershell > recursivist.ps1
Advanced Usage
Using with Git Repositories
When working with Git repositories, you can use your existing .gitignore file:
recursivist visualize \
--ignore-file .gitignore
Integration with Other Tools
The JSON export format allows for easy integration with other tools:
# Export to JSON
recursivist export \
--format json \
--prefix myproject
# Use with jq for additional processing
cat myproject.json | jq '.structure | keys'
Development
Setting Up Development Environment
# Clone the repository
git clone https://github.com/ArmaanjeetSandhu/recursivist.git
cd recursivist
# Create a virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install development dependencies
pip install -e ".[dev]"
Running Tests
# Run tests
pytest
Building the Package
# Install build tools
pip install build
# Build the package
python -m build
Testing
The Recursivist project uses pytest for testing. The test suite covers core functionality, CLI interface, export features, comparison functionality, regex pattern matching, and depth limiting.
Running Tests
To run the tests, first install the development dependencies:
pip install -e ".[dev]"
Then run the tests with:
pytest
You can also run specific test files:
# Run only core tests
pytest test_core.py
# Run only export tests
pytest test_exports.py
# Run only CLI tests
pytest test_cli.py
# Run only compare tests
pytest test_compare.py
# Run regex pattern tests
pytest test_regex.py
# Run depth limit tests
pytest test_depth.py
# Run integration tests
pytest test_integration.py
Test Coverage
To generate a detailed coverage report:
pytest \
--cov=recursivist \
--cov-report=html
This will create an HTML coverage report in the htmlcov directory, which you can open in your browser.
Continuous Integration
The test suite is automatically run on GitHub Actions for every pull request and push to the main branch. This ensures that all changes maintain compatibility and don't introduce regressions.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
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
Acknowledgements
Author
Armaanjeet Singh Sandhu
- Email: armaanjeetsandhu430@gmail.com
- GitHub: ArmaanjeetSandhu
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file recursivist-1.0.0.tar.gz.
File metadata
- Download URL: recursivist-1.0.0.tar.gz
- Upload date:
- Size: 46.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
afc84e00a6ec00162d8adede1b43bca186e8cf7042141252ff11b086db43c7e9
|
|
| MD5 |
15985dd5b072d7310492ac4302cae891
|
|
| BLAKE2b-256 |
6920e62c2644034d1e75f77f80d539883b842a3cac67a604fc31defbdc963305
|
File details
Details for the file recursivist-1.0.0-py3-none-any.whl.
File metadata
- Download URL: recursivist-1.0.0-py3-none-any.whl
- Upload date:
- Size: 27.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
328cf3983780f04382b40c5f67e97d51fec39008e5e929782db4800050b45610
|
|
| MD5 |
ed255eff09f9d262ed6abadc28f8b5a8
|
|
| BLAKE2b-256 |
9f440825cc44e8443e2136384ecb8401bb6bccac5c3c046184845fca2680eb14
|