LinuxCommandLibrary

treemd

TLDR

Open a markdown file in interactive TUI mode

$ treemd [path/to/file.md]
copy

List all headings in a markdown file
$ treemd [[-l|--list]] [path/to/file.md]
copy

Show the heading tree structure of a markdown file
$ treemd --tree [path/to/file.md]
copy

Extract a specific section by heading name
$ treemd [[-s|--section]] [heading_name] [path/to/file.md]
copy

Filter headings by a specific pattern
$ treemd [[-l|--list]] --filter [pattern] [path/to/file.md]
copy

Query and extract markdown structure using the treemd query language
$ treemd [[-q|--query]] '[.h2 | text]' [path/to/file.md]
copy

SYNOPSIS

treemd [OPTIONS] [DIR]

PARAMETERS

-h, --help
    Show help message and exit.

-V, --version
    Display program version.

-f, --file FILE
    Output to file (default: tree.md)

-i, --indent INT
    Set indent size (default: 2)

-d, --dirsfirst
    List directories before files.

-D, --maxdepth INT
    Limit maximum depth (default: unlimited)

--gitignore
    Respect .gitignore patterns.

--gitattributes
    Respect .gitattributes patterns.

-I, --ignore PATTERN
    Ignore matching files/dirs (repeatable).

-E, --exclude PATTERN
    Exclude matching files/dirs (repeatable).

DESCRIPTION

treemd is a command-line utility that scans a directory and produces a visually appealing tree structure output in Markdown format. Ideal for GitHub README files, project documentation, or any scenario needing a quick overview of folder hierarchies.

It supports customization like ignoring common directories (e.g., node_modules, .git), limiting depth, and respecting .gitignore files. The output is hierarchical with Unicode box-drawing characters, branches, and proper indentation, rendering beautifully in Markdown viewers.

Unlike the standard tree command, treemd focuses on Markdown export, making it perfect for static site generators, wikis, or code repos. Install via pip (pip install treemd) or cargo for Rust versions. Usage is straightforward, outputting to stdout or a file like tree.md.

CAVEATS

Not a standard Linux utility; requires installation (e.g., pip install treemd). Output uses Unicode, may not render in all terminals. Relative paths in output.

EXAMPLE

treemd . -f README.md --gitignore
Generates tree.md in current dir, ignoring git files.

INSTALLATION

Python: pip install treemd
Rust: cargo install treemd

HISTORY

Developed by newAM as a Python CLI tool (GitHub: newAM/treemd, ~2019). Inspired by tree command. Available on PyPI; Rust ports exist for performance.

SEE ALSO

tree(1), ls(1), find(1)

Copied to clipboard