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

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.0.tar.gz (28.9 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.0-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ltree_cli-0.2.0.tar.gz
  • Upload date:
  • Size: 28.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for ltree_cli-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e46c7a17caf7b074a3c24eff271e14a7548dbc20ebd481f15414e7df5b473612
MD5 2a6daf98bb33940e6b118f51e7967c82
BLAKE2b-256 d15342b7350b96dcb468fc7dad5ecdcdddfb76cd5a3d0ab2e3b09edc0ee8a3cf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ltree_cli-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 20.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for ltree_cli-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a5e916a93c9b06ce6e1c7aed2e68daebf188d548f767d8194c27b709a5665268
MD5 947b255a5cd78bc1bcfc7d2185921b1a
BLAKE2b-256 44fecd950e2bbd20c19783afc345d20c10428a4c69992e938bff8b08bc1eb4a6

See more details on using hashes here.

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