Skip to content

Anuar-boop/tree-printer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tree-printer

Rust License: MIT No Dependencies

A fast, feature-rich directory tree printer written in Rust. Displays directory structures with color output, gitignore awareness, and multiple output formats.

Zero external dependencies -- uses only the Rust standard library.

Features

  • Color output -- syntax-highlighted file names by extension
  • Depth limit -- control how deep to traverse
  • File size display -- show human-readable file sizes
  • Gitignore-aware -- respects .gitignore rules automatically
  • Pattern filtering -- include or exclude files by glob pattern
  • Sort options -- sort by name, size, or date
  • Hidden files toggle -- show or hide dotfiles
  • Multiple output formats -- text (with Unicode tree), JSON, Markdown
  • Directory stats -- total files, directories, and size summary
  • Dirs/files only -- filter to show only directories or only files

Installation

From Source

git clone https://github.com/Anuar-boop/tree-printer.git
cd tree-printer
cargo build --release
cp target/release/tree-printer /usr/local/bin/

Usage

Basic

tree-printer

Output:

my-project/
+-- src/
|   +-- main.rs
|   +-- lib.rs
|   +-- utils/
|       +-- helpers.rs
+-- tests/
|   +-- integration.rs
+-- Cargo.toml
+-- README.md

3 directories, 5 files, 12.4 KB total

With Options

# Limit depth to 2 levels
tree-printer -d 2

# Show file sizes
tree-printer -s

# Show hidden files
tree-printer -a

# Sort by file size
tree-printer --sort size

# Show only Rust files
tree-printer --include '*.rs'

# Exclude build artifacts
tree-printer --exclude target --exclude '*.o'

# JSON output
tree-printer --format json > tree.json

# Markdown output
tree-printer --format markdown > TREE.md

# Specific directory
tree-printer /path/to/project -d 3 -s

# Directories only
tree-printer --dirs-only

# Disable color (for piping)
tree-printer --no-color | less

# Ignore gitignore rules
tree-printer --no-gitignore -a

JSON Output

tree-printer --format json
{
  "name": "my-project",
  "type": "directory",
  "children": [
    {
      "name": "src",
      "type": "directory",
      "children": [
        {
          "name": "main.rs",
          "type": "file",
          "size": 2048
        }
      ]
    }
  ],
  "stats": {
    "directories": 3,
    "files": 5,
    "total_bytes": 12680
  }
}

Markdown Output

tree-printer --format markdown -s
# my-project/

- **src/**
  - main.rs *(2.0 KB)*
  - lib.rs *(1.5 KB)*
  - **utils/**
    - helpers.rs *(856 B)*
- **tests/**
  - integration.rs *(1.2 KB)*
- Cargo.toml *(245 B)*
- README.md *(3.4 KB)*

---
*3 directories, 5 files, 12.4 KB total*

CLI Reference

USAGE:
    tree-printer [OPTIONS] [PATH]

ARGS:
    [PATH]                Directory to print (default: current directory)

OPTIONS:
    -d, --depth <N>       Maximum depth to display
    -s, --size            Show file sizes
    -a, --all             Show hidden files (dotfiles)
    --no-color            Disable color output
    --no-gitignore        Don't respect .gitignore rules
    --sort <MODE>         Sort by: name (default), size, date
    --format <FMT>        Output format: text (default), json, markdown
    --include <PATTERN>   Only show files matching pattern (repeatable)
    --exclude <PATTERN>   Hide files matching pattern (repeatable)
    --dirs-only           Only show directories
    --files-only          Only show files
    -h, --help            Show help message
    -v, --version         Show version

Color Legend

Color File Type
Blue (bold) Directories
Green Source code (.rs, .py, .js, .go, .java, etc.)
Yellow Documentation (.md, .txt, .pdf)
Cyan Config files (.json, .yaml, .toml, .ini)
Magenta Images (.png, .jpg, .svg)
Red Shell scripts (.sh, .bash)
Dim Lock files (.lock, .sum)

License

MIT

Releases

No releases published

Packages

 
 
 

Contributors

Languages