Skip to main content

A modern, beautiful and powerful command-line directory tree generator with advanced filtering and code-viewing capabilities.

Project description

Treely ๐ŸŒณ

A modern, beautiful, and powerful command-line directory tree generator. treely goes beyond a simple tree command by offering smart filtering, automatic .gitignore parsing, and a killer feature: the ability to output the contents of your code files, ready to be saved, shared, or copied directly to your clipboard.

It's the perfect tool for scaffolding a project's structure for documentation, preparing context for AI/LLM prompts, or getting a high-level overview of a new codebase.

PyPI version License: MIT Python Versions GitHub stars

Treely Demo GIF

(Note: The demo GIF shows an older version!)

๐ŸŒŸ Key Features

  • Elegant Tree Structure: Generates a clean, easy-to-read directory tree with colorful output.
  • Intelligent Code Printing: Use the --code flag to display the full contents of all relevant code files directly after the tree structure.
  • Automatic .gitignore Support: The --use-gitignore flag intelligently and automatically excludes files and directories specified in your .gitignore file. No more manual --ignore flags for node_modules or dist!
  • Export & Share:
    • Copy to Clipboard (-c): Instantly copy the entire tree and code output to your clipboard, perfect for pasting into LLM prompts (like GPT), GitHub issues, or pull requests.
    • Save to File (-o): Save the clean, colorless output directly to a file for documentation or artifacts.
  • Advanced Filtering & Display:
    • Limit the tree depth (-L).
    • Filter by glob patterns (--pattern).
    • Manually ignore files and directories (--ignore).
    • Display file sizes (--show-size).
    • Get a project summary (-s).
  • Cross-Platform: Works seamlessly on Windows, macOS, and Linux.

๐Ÿ“ฆ Installation

You can install treely directly from PyPI. The necessary dependencies (pyperclip and pathspec) will be installed automatically.

pip install treely

Ensure that your Python scripts directory is in your system's PATH to run treely from anywhere.

๐Ÿš€ Usage

Basic Command

To generate a tree for the current directory:

treely

For a specific directory:

treely /path/to/your/project

Command-line Options

usage: treely [-h] [-a] [-L LEVEL] [--pattern PATTERN] [--ignore PATTERNS] [--code [IGNORE_PATTERNS]] [--use-gitignore] [-s]
              [--show-size] [-o [FILENAME]] [-c]
              [root_path]

A beautiful and professional directory tree generator.

positional arguments:
  root_path             The starting folder for the tree. Uses current folder if not specified.

options:
  -h, --help            show this help message and exit
  -a, --all             Show all items, including hidden ones (e.g., '.git').
  -L LEVEL, --level LEVEL
                        How many folders deep to look (e.g., -L 2).
  --pattern PATTERN     Show only files/folders that match a pattern (e.g., "*.py").
  --ignore PATTERNS     Don't show items matching a pattern. Use '|' to separate (e.g., "__pycache__|*.tmp").
  --code [IGNORE_PATTERNS]
                        Display code file content after the tree. Use alone for all code, or with patterns to exclude (e.g., --code
                        "file1.py|file2.js").
  --use-gitignore       Automatically ignore files and directories listed in .gitignore.
  -s, --summary         Print a summary of the number of directories and files.
  --show-size           Display the size of each file.
  -o [FILENAME], --output [FILENAME]
                        Save the output to a file. Defaults to 'treely_output.txt' if no name is given. Banner and colors are excluded.
  -c, --copy            Copy the output to the clipboard. Banner and colors are excluded.

Examples:
  # Generate a tree for the current folder
  treely

  # Use the project's .gitignore to automatically exclude files
  treely --use-gitignore

  # Generate a tree 2 levels deep and save it to a file
  treely -L 2 -o my_project_tree.md

  # Show file sizes and a summary of contents
  treely --show-size -s

  # Show tree and copy all code content to clipboard, ignoring 'node_modules'
  treely --ignore "node_modules" --code -c

  # Show only python files, print their content (except config.py), and copy
  treely --pattern "*.py" --code "config.py" -c

โœจ Workflow Examples

Let's use the following project structure for our examples. The .gitignore file contains node_modules/ and .env.

my-web-app/
โ”œโ”€โ”€ .git/
โ”œโ”€โ”€ node_modules/
โ”‚   โ””โ”€โ”€ ... (many files)
โ”œโ”€โ”€ public/
โ”‚   โ””โ”€โ”€ index.html
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ App.js
โ”‚   โ””โ”€โ”€ index.js
โ”œโ”€โ”€ .env
โ”œโ”€โ”€ .gitignore
โ””โ”€โ”€ package.json

1. The Smart Default: Using .gitignore

This is the recommended way to get a clean overview of any project. treely will read your .gitignore and automatically exclude node_modules/ and .env.

Command:

treely my-web-app --use-gitignore

Output:

... (banner) ...
my-web-app/
โ”œโ”€โ”€ public/
โ”‚   โ””โ”€โ”€ index.html
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ App.js
โ”‚   โ””โ”€โ”€ index.js
โ”œโ”€โ”€ .gitignore
โ””โ”€โ”€ package.json

Notice how .git, node_modules, and .env are all gone with one simple flag!

2. Create Project Documentation

Generate a complete project overview with file sizes and a summary, and save it directly to a Markdown file. This is perfect for a README or project wiki.

Command:

treely my-web-app --use-gitignore --show-size -s -o project_structure.md

Console Message:

... (banner) ...
โœ” Output successfully saved to project_structure.md

Contents of project_structure.md:

my-web-app/
โ”œโ”€โ”€ public/
โ”‚   โ””โ”€โ”€ index.html  [345B]
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ App.js  [512B]
โ”‚   โ””โ”€โ”€ index.js  [230B]
โ”œโ”€โ”€ .gitignore  [15B]
โ””โ”€โ”€ package.json  [780B]

2 directories, 5 files

3. Prepare an AI/LLM Prompt

This is treely's superpower. Generate a complete project context (structure and all relevant code) and copy it directly to your clipboard. You are now ready to paste it into ChatGPT, Claude, or any other LLM.

Command:

treely my-web-app --use-gitignore --code -c

Console Message:

... (banner) ...
โœ” Tree structure copied to clipboard.

Your clipboard now contains the full tree and the contents of index.html, App.js, index.js, and package.json, perfectly formatted.

4. Advanced Filtering and Code View

Generate a tree showing only JavaScript files and print their contents, but exclude index.js from the code output.

Command:

treely my-web-app --pattern "*.js" --code "index.js"

Output: This will show a tree with only App.js and index.js, but the --- FILE CONTENTS --- section will only contain the code for App.js.

๐Ÿค Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

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

treely-1.1.0.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

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

treely-1.1.0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file treely-1.1.0.tar.gz.

File metadata

  • Download URL: treely-1.1.0.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for treely-1.1.0.tar.gz
Algorithm Hash digest
SHA256 13b15780a37df5dc1707850a4a685bc959b1faacda1dba5fd516a6a24d0171e7
MD5 161bc7f9571314056e0ac79b91c12ba5
BLAKE2b-256 97fc26b130b0ac666040256b6ab4bb83e98844f46b9ae494369a38687e9192a5

See more details on using hashes here.

File details

Details for the file treely-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: treely-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for treely-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 549f7ab2437e3028461861cac77b23e0d4a2b81b47ce6e0486800087c840607a
MD5 7b7a0804d62a50c956df4f74f1575ed8
BLAKE2b-256 07f2600a8d56cdf655530a3b7c52398a62f2d69511dcf41242261c5eadd0399e

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