Skip to main content

A customizable tree-like directory viewer with filtering, depth control, and statistics

Project description

ltree

ltree is a fast, customizable CLI tool to visualize directory structures in a tree diagram. It features beautiful Rich UI rendering, Nerd Font/Emoji icon support, detailed statistics, and multiple export formats.

>>> ltree .
๐Ÿ“‚ ltree/
โ”œโ”€โ”€ โš–๏ธ LICENSE
โ”œโ”€โ”€ ๐Ÿ“‚ ltree/
โ”‚   โ”œโ”€โ”€ ๐Ÿ __init__.py
โ”‚   โ”œโ”€โ”€ ๐Ÿ cli.py
โ”‚   โ”œโ”€โ”€ ๐Ÿ constants.py
โ”‚   โ”œโ”€โ”€ ๐Ÿ“‚ core/
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ __init__.py
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ config.py
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ models.py
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ scanner.py
โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ utils.py
โ”‚   โ”œโ”€โ”€ ๐Ÿ“‚ renderers/
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ __init__.py
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ base.py
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ exporters.py
โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ rich_renderer.py
โ”‚   โ””โ”€โ”€ ๐Ÿ“‚ themes/
โ”‚       โ”œโ”€โ”€ ๐Ÿ __init__.py
โ”‚       โ”œโ”€โ”€ ๐Ÿ emoji.py
โ”‚       โ”œโ”€โ”€ ๐Ÿ icons.py
โ”‚       โ””โ”€โ”€ ๐Ÿ nerd.py
โ”œโ”€โ”€ ๐Ÿ“‚ ltree-vscode/
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ CHANGELOG.md
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ eslint.config.mjs
โ”‚   โ”œโ”€โ”€ โš™๏ธ package-lock.json
โ”‚   โ”œโ”€โ”€ โš™๏ธ package.json
โ”‚   โ”œโ”€โ”€ ๐Ÿ“– README.md
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ฆ src/
โ”‚   โ”‚   โ””โ”€โ”€ ๐ŸŸฆ extension.ts
โ”‚   โ””โ”€โ”€ โš™๏ธ tsconfig.json
โ”œโ”€โ”€ โš™๏ธ pyproject.toml
โ”œโ”€โ”€ ๐Ÿ“– README.md
โ”œโ”€โ”€ ๐Ÿงช tests/
โ”‚   โ”œโ”€โ”€ ๐Ÿ __init__.py
โ”‚   โ”œโ”€โ”€ ๐Ÿ test_cli.py
โ”‚   โ”œโ”€โ”€ ๐Ÿ test_config.py
โ”‚   โ”œโ”€โ”€ ๐Ÿ test_core.py
โ”‚   โ”œโ”€โ”€ ๐Ÿ test_exporters.py
โ”‚   โ”œโ”€โ”€ ๐Ÿ test_icons.py
โ”‚   โ”œโ”€โ”€ ๐Ÿ test_rich_renderer.py
โ”‚   โ””โ”€โ”€ ๐Ÿ test_utils.py
โ””โ”€โ”€ ๐Ÿ”’ uv.lock

Summary:
Visible:   7 directories,  35 files
Total  :   7 directories,  35 files

Installation

You can install ltree directly from PyPI:

# Using pip
pip install ltree-cli

# Or using uv
uv pip install ltree-cli

For local development or usage:

# Clone the repository
git clone https://github.com/YuHao-Yeh/ltree.git
cd ltree

# Install in editable mode (using uv)
uv pip install -e .

# Or using standard pip
pip install -e .

VS Code Extension

ltree now comes with an official VS Code companion!

  • Quick Action: Right-click any file or folder in the Explorer to generate a tree.
  • Multiple Formats: Copy as Text, JSON, or Markdown Blocks (perfect for AI prompts).
  • Customizable: Pass any CLI arguments directly from VS Code.

To use it, check the ltree-vscode directory for installation instructions.


Usage

ltree [path] [options]

Basic Commands

# Display current directory structure
ltree

# Output to console with color
ltree . -o - --color

# Save tree to a file
ltree /path/to/dir -o tree.txt

# For more help
ltree --help

Quick Examples

Click to expand examples
  • Export to JSON: ltree -F json -o data.json
  • Markdown List: ltree -F md -o report.md
  • Markdown Block: ltree -F block -o report.md
  • Limit Depth: ltree -L 2 --show-ellipsis
  • Filter by Extension: ltree --ex-ext .log --ex-ext .tmp
  • Filter by Regex: ltree --re-ex "test_.*\.py"
  • Only Directories: ltree -d --dirs-first
  • Show Sizes: ltree -s -H
  • Nerd Fonts and Rich UI: ltree . -F rich --theme nerd

Options

Run ltree --help to see the full list of available options.

View Full Parameter List

Basic Options

Argument Short Default Description
start_path . Starting directory path.
--output -o - Output file name. Use - for stdout.

Output Formatting & Display

Argument Short Default Description
--format -F text Choices: text, json, md, markdown, block, rich.
--theme emoji Icon theme to use. Choices: emoji, nerd, none.
--color -c Enable colored output.
--size -s Show file/directory sizes.
--human -H Show size in human-readable format (e.g., 1K, 2M).

Filtering Rules

Argument Short Description
--all -a Show hidden files and directories (starting with .).
--dirs-only -d Only display directories.
--ex-dirs Exclude specific directories.
--ex-files -I Exclude files (supports wildcards like *.log).
--ex-ext Exclude by file extension (e.g., .log).
--ex-prefix Exclude items by prefix.
--re-ex Exclude paths matching a regular expression.
--no-ignore Disable automatic exclusion based on .gitignore (enabled by default).
--add-dirs Re-include specific directories previously excluded.
--add-files Re-include specific files previously excluded.

Display Options

Argument Short Description
--max-depth -L Limit directory recursion depth.
--full-path -f Print the full path prefix for every entry.
--dirs-first List directories before files.
--show-ellipsis Show "..." when depth is truncated.

Configuration

You can save your favorite settings in a config file so you don't have to type them every time. ltree will automatically search for these files in your project directory (or climb up to find them):

  • .ltreerc (JSON)
  • pyproject.toml (under [tool.ltree])

Configuration Priority

Settings are merged and overridden in the following order (from highest to lowest priority):

  1. Command Line Arguments
  2. Local Configuration File (.ltreerc or pyproject.toml)
  3. Default Settings

Examples

.ltreerc (JSON)

Create a .ltreerc file in your project root:

{
  "theme": "nerd",
  "size": true,
  "human": true,
  "dirs_first": true,
  "ex_dirs": ["dist", "build", "target"],
  "ex_ext": [".log", ".tmp"]
}

pyproject.toml (TOML)

Create a pyproject.toml file in your project root:

[tool.ltree]
theme = "emoji"
full_path = true
color = true
size = true
add_dirs = ["output", "temp"]

Supported Configuration Keys

All command-line flags can be configured in your settings file:

  • Booleans & Strings:
    • theme: "emoji", "nerd", or "none"
    • color, size, human, all (show hidden files), dirs_only, full_path, dirs_first, show_ellipsis, no_ignore
  • Filter Rules:
    • ex_dirs, ex_files, ex_ext, ex_prefix, add_dirs, add_files

Output Examples

Standard Text

ltree/
โ”œโ”€โ”€ ltree/
โ”‚   โ”œโ”€โ”€ core.py
โ”‚   โ””โ”€โ”€ exporters.py
โ”œโ”€โ”€ tests/
โ””โ”€โ”€ README.md

Summary:
Visible:   2 directories,   3 files
Total  :   2 directories,   3 files

Rich UI & Nerd Fonts (-F rich --theme nerd)

๏ป ltree/
โ”œโ”€โ”€ ๏ป ltree/
โ”‚   โ”œโ”€โ”€ ๎˜† core.py
โ”‚   โ””โ”€โ”€ ๎˜† exporters.py
โ”œโ”€โ”€ ๏’™ tests/
โ””โ”€โ”€ ๏’Š README.md

Markdown Mode (-F md)

  • ๐Ÿ“‚ ltree/
    • ๐Ÿ core.py
    • ๐Ÿ exporters.py
  • ๐Ÿ“‚ tests/
  • ๐Ÿ“– README.md

License

Distributed under the MIT License. See LICENSE for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ltree_cli-0.2.1.tar.gz (28.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ltree_cli-0.2.1-py3-none-any.whl (20.2 kB view details)

Uploaded Python 3

File details

Details for the file ltree_cli-0.2.1.tar.gz.

File metadata

  • Download URL: ltree_cli-0.2.1.tar.gz
  • Upload date:
  • Size: 28.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ltree_cli-0.2.1.tar.gz
Algorithm Hash digest
SHA256 543b48a472a903b9631e1109df040b07960cf7aed180a9d72c1bef6c1813313c
MD5 f315213b0768ce58b54963d21466648d
BLAKE2b-256 dee9f3cf0eeb0625fae25e931f6a6dda7a6b1ecb1ecec559295ffe14bd6f6d1c

See more details on using hashes here.

Provenance

The following attestation bundles were made for ltree_cli-0.2.1.tar.gz:

Publisher: publish.yml on YuHao-Yeh/ltree

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ltree_cli-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: ltree_cli-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 20.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ltree_cli-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a88433852e45086ad9b01bb24ce596435b1f363387ff94c0885442aa174dac22
MD5 beb60c3e1d8f100223fb0348ecee2e7f
BLAKE2b-256 c0e725b8192fc8e424caaf5517117b7934f9a6e66598babd62f6726d482a9cc5

See more details on using hashes here.

Provenance

The following attestation bundles were made for ltree_cli-0.2.1-py3-none-any.whl:

Publisher: publish.yml on YuHao-Yeh/ltree

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page