chezmoi-files
A command-line utility and Rust library that generates colorized tree visualizations of file paths. It reads file paths from stdin, filters them based on configurable glob patterns, and outputs a hierarchical tree structure with syntax-highlighted file names.
Perfect for use with chezmoi to visualize your dotfiles, or with any tool that outputs file paths. Can also be used as a library in your own Rust projects.
Features
- Glob Pattern Filtering: Advanced pattern matching with wildcards (
*,?,[abc],[a-z]) - Customizable Colors: Configure colors for folders, files, and specific extensions
- Multiple Sorting Options: Sort by name, type, or keep original order
- Statistics: Display counts of files, directories, and excluded items
- Fast: Optimized Rust implementation with minimal overhead
- Configurable: Simple TOML configuration file
- Well-tested: 89.61% code coverage with 83 tests
Installation
From crates.io
From source
Pre-built binaries
Download pre-built binaries from the releases page.
Usage
As a Command-Line Tool
Pipe file paths into the program:
# Basic usage
|
# With chezmoi
|
# From a file list
|
The program expects one file path per line on stdin. It will:
- Filter paths based on exclusion patterns
- Strip the current directory prefix to create relative paths
- Build a tree structure
- Display it with syntax-highlighted file names
Command-Line Options
# Disable colorized output
|
# Show statistics (file and directory counts)
|
# Sort output by name
|
# Sort output by type (directories first, then by extension)
|
# Combine options
|
Configuration Commands
# Show current configuration location and contents
# Output the default configuration
# Initialize configuration file with defaults
As a Library
Add to your Cargo.toml:
[]
= "0.7"
Use in your code:
use ;
// Create a tree structure
let mut root = new;
root.add_path;
root.add_path;
root.add_path;
// Load configuration
let config = default ;
// Create color scheme
let color_scheme = new;
// Check if paths should be excluded
if config.is_excluded
See the API documentation for more details.
Configuration
The program reads configuration from:
~/.config/chezmoi/chezmoi-files.toml
An example configuration file is provided as chezmoi-files.toml.example. Copy it to the config location and customize
as needed.
Configuration Format
The config file uses TOML format with two sections:
[]
= [
"DS_Store",
"fish_variables",
".rubocop.yml",
".ruff_cache",
"yazi.toml-",
".zcompcache",
".zcompdump",
".zsh_history",
"plugins/fish",
"plugins/zsh",
]
[]
= []
Pattern Matching
Patterns support glob-style wildcards:
*- Matches any sequence of characters?- Matches any single character[abc]- Matches any character in the set[a-z]- Matches any character in the range
Examples:
*.tmp- Matches any file ending in.tmpcache/*- Matches any file in a cache directorytest_?.rs- Matchestest_1.rs,test_a.rs, etc.fish_variables*- Matchesfish_variables,fish_variables.bak, etc.
Exclusion Logic:
- Paths matching exclusion patterns are filtered out
- Paths matching inclusion patterns override exclusions (whitelist)
- Patterns without wildcards use substring matching for backward compatibility
Default Exclusions
If no config file exists, these patterns are excluded by default:
DS_Storefish_variables.rubocop.yml.ruff_cacheyazi.toml-.zcompcache.zcompdump.zsh_historyplugins/fishplugins/zsh
Color Scheme
Default Colors
Files are colorized based on their extension:
- Folders: White
- Shell scripts (.sh, .bash, .zsh, .fish, .nu): Green
- Config files (.toml, .yaml, .yml, .json, .xml, .ini, .conf): Yellow
- Documentation (.md, .txt, .rst): Cyan
- Source code (.rs, .py, .js, .ts, .go, .c, .cpp, .java, .jl): Red
- Plists (.plist, .sublime): Magenta
- Default: Blue
Customizing Colors
You can customize colors in the configuration file:
[]
= true
= "white"
= "blue"
[]
= "red"
= "green"
= "cyan"
Available color names: black, red, green, yellow, blue, magenta, cyan, white
You can also use custom ANSI codes for more control.
Examples
Basic directory tree
|
Output:
.
├── src
│ ├── main.rs
│ └── lib.rs
└── tests
└── test.rs
With chezmoi
|
This displays all files managed by chezmoi in a tree structure, excluding patterns from your config file.
Requirements
- Rust 1.92.0 or later
- Input must be piped (the program will exit if stdin is a terminal)
Testing
The project has comprehensive test coverage with 83 tests achieving 89.61% overall coverage:
# Run all tests
# Generate coverage report
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
Development
# Clone the repository
# Run tests
# Run with coverage
# Run clippy
Similar Projects
- tree - The classic Unix tree command
- eza - Modern replacement for ls with tree view
- broot - Interactive tree view
License
Licensed under the Apache License, Version 2.0 (LICENSE or http://www.apache.org/licenses/LICENSE-2.0)
Acknowledgments
- Tree rendering algorithm derived from eza (MIT License)
- Built with Rust's excellent ecosystem