Skip to content
/ treex Public

๐ŸŒณโŒ: Treex is a CLI for directory structure visualization in various formats with powerful filters.

License

Notifications You must be signed in to change notification settings

shiquda/treex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

26 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŒณโŒ Treex

Go Version License Release Go Report Card

Treex

็ฎ€ไฝ“ไธญๆ–‡

Treex is a powerful command-line tool for displaying directory structures in different formats. It offers multiple output formats and flexible filtering options, making it easy to visualize and explore your project layout.

โœจ Features

  • ๐ŸŽจ Multiple output formats:
    • ๐ŸŒฒ tree: Tree format (default)
    • ๐Ÿ“‘ indent: Indented list format
    • ๐Ÿ“ md: Markdown format
    • ๐Ÿ“Š mermaid: Mermaid format
    • ๐Ÿ”— json: JSON format
    • ๐Ÿ“Š csv: CSV format
  • ๐Ÿ” Flexible filtering options:
    • ๐Ÿ•ต๏ธ -H: Hide hidden files and directories
    • ๐Ÿ“ -D: Show directories only
    • ๐Ÿšซ -e <rules>: Exclude specific directories or file extensions
    • ๐Ÿ“ -I: Automatically apply .gitignore rules
  • ๐Ÿ› ๏ธ Customizable output:
    • ๐Ÿ“ -m <depth> or -L <depth>: Control directory depth
    • ๐Ÿ’พ -o <path>: Save output to a file
    • ๐ŸŽฏ -f <format>: Select output format
    • โญ -C: Show icons for files (via emoji)
  • ๐Ÿ“Š File metadata display:
    • ๐Ÿ“ -s: Show file sizes (human-readable format)
    • ๐Ÿ‘ค -O: Show file owners
    • ๐Ÿ• -M: Show file modification times
  • ๐Ÿ”ง Enhanced compatibility:
    • ๐ŸŒ Improved Windows pipe support with UTF-8 encoding
    • ๐ŸŽฏ -L as alias for -m for better tree command compatibility

๐Ÿ“ฆ Installation

Download the pre-built binary from the releases page and add it to your PATH.

Or, if you want to build it yourself with Go:

go install github.com/shiquda/treex@latest

For windows user, you can use scoop to install treex:

scoop bucket add extras
scoop install treex

๐Ÿ“– Usage

Basic usage:

treex -d <directory>

To generate a tree for the current directory, simply run:

treex

โš™๏ธ Full Options

You can run treex -h to see the help message.

All command-line options are listed in the table below:

Short Option Long Option Argument Description Default Value
-d --dir <directory> Directory to scan .
-f --format <format> Output format (tree, indent, md, mermaid, json, csv) tree
-m --max-depth <number> Maximum directory depth (0 for unlimited) -
-L --level <number> Maximum directory depth (0 for unlimited, alias for -m) -
-s --size - Show file sizes (human-readable format) false
-O --owner - Show file owners false
-M --modtime - Show file modification times false
-o --output <filepath> Path to output file stdout
-e --exclude <rules> Exclude rules (comma-separated: dir/ for dirs, .ext for extensions) -
-H --hide-hidden - Hide hidden files and directories false
-D --dirs-only - Show directories only false
-I --use-gitignore - Exclude files/directories based on .gitignore false
-C --icons - Show file type icons false

Format options details:

  • tree: Tree structure with branches
  • indent: Indented list format
  • md: Markdown format
  • mermaid: Mermaid format for diagrams
  • json: JSON format with structured data
  • csv: CSV format for spreadsheet applications

Exclude rules format:

  • dir/: Exclude directories matching the specified name
  • .ext: Exclude files with the specified extension

๐Ÿ“š Examples

The following examples use the same directory structure.

  1. Without hidden files, save output as markdown format:
treex -H -f md -o structure.md
  • -H: Hide hidden files and directories
  • -f md: Output in Markdown format
  • -o structure.md: Save output to structure.md file
Result:

Then in ./structure.md:

- ./
  - 1.go
  - 2.go
  - README.md
  - build/
    - win/
      - output.exe
  - test/
    - 3.go
    - README_test.md
  1. Use .gitignore rules to exclude files:

.gitignore:

build/

Run:

treex -IH
  • -I: Exclude files/directories based on .gitignore
  • -H: Hide hidden files and directories

This will automatically read the .gitignore file in the current directory and exclude matching files and directories.

Result:
.
โ”œโ”€โ”€ 1.go
โ”œโ”€โ”€ 2.go
โ”œโ”€โ”€ README.md
โ””โ”€โ”€ test
    โ”œโ”€โ”€ 3.go
    โ””โ”€โ”€ README_test.md
  1. Generate mermaid diagram for visible directories only:
treex -HD -f mermaid
  • -H: Hide hidden files and directories
  • -D: Show directories only
  • -f mermaid: Output in Mermaid diagram format
Result:
graph TD
    N1[./]
    N2[build/]
    N1 --> N2
    N3[win/]
    N2 --> N3
    N4[test/]
    N1 --> N4
Loading
  1. Exclude specific directories or extensions:
treex -e ".git/, .md"
  • -e ".git/, .md": Exclude .git directory and files with .md extension
Result:
.
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ 1.go
โ”œโ”€โ”€ 2.go
โ”œโ”€โ”€ build
โ”‚   โ””โ”€โ”€ win
โ”‚       โ””โ”€โ”€ output.exe
โ””โ”€โ”€ test
    โ””โ”€โ”€ 3.go
  1. Show files up to depth 2 in indent mode:
treex -m 2 -f indent
  • -m 2: Show files up to depth 2
  • -f indent: Output in indented list format
Result:
./
    .git/
        HEAD
        config
        description
        hooks/
        info/
        objects/
        refs/
    .gitignore
    1.go
    2.go
    README.md
    build/
        win/
    test/
        3.go
        README_test.md
  1. Display the file structure with icons (using a real project structure as an example):
treex -CHI -m 3
  • -C: Show file type icons
  • -H: Hide hidden files and directories
  • -I: Exclude files/directories based on .gitignore
  • -m 3: Show files up to depth 3
Result:
๐Ÿ“ ./
โ”œโ”€โ”€ ๐Ÿ“ CODE_OF_CONDUCT.md
โ”œโ”€โ”€ ๐Ÿ“ CONTRIBUTING.md
โ”œโ”€โ”€ ๐Ÿ“„ LICENSE
โ”œโ”€โ”€ ๐Ÿ“ README.md
โ”œโ”€โ”€ ๐Ÿ“ build/
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ entitlements.mac.plist
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ icon.icns
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ icon.ico
โ”‚   โ”œโ”€โ”€ ๐Ÿ–ผ๏ธ icon.png
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ icons/
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ–ผ๏ธ 1024x1024.png
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ–ผ๏ธ 128x128.png
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ–ผ๏ธ 16x16.png
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ–ผ๏ธ 24x24.png
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ–ผ๏ธ 256x256.png
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ–ผ๏ธ 32x32.png
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ–ผ๏ธ 48x48.png
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ–ผ๏ธ 512x512.png
โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ–ผ๏ธ 64x64.png
โ”‚   โ”œโ”€โ”€ ๐Ÿ–ผ๏ธ logo.png
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ nsis-installer.nsh
โ”‚   โ”œโ”€โ”€ ๐Ÿ–ผ๏ธ tray_icon.png
โ”‚   โ”œโ”€โ”€ ๐Ÿ–ผ๏ธ tray_icon_dark.png
โ”‚   โ””โ”€โ”€ ๐Ÿ–ผ๏ธ tray_icon_light.png
โ”œโ”€โ”€ โš™๏ธ dev-app-update.yml
โ”œโ”€โ”€ ๐Ÿ“ docs/
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ README.ja.md
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ README.zh.md
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ dev.md
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ sponsor.md
โ”‚   โ””โ”€โ”€ ๐Ÿ“ technical/
โ”‚       โ””โ”€โ”€ ๐Ÿ“ KnowledgeService.md
โ”œโ”€โ”€ โš™๏ธ electron-builder.yml
โ”œโ”€โ”€ ๐Ÿ“œ electron.vite.config.ts
โ”œโ”€โ”€ ๐Ÿ“„ eslint.config.mjs
โ”œโ”€โ”€ ๐Ÿ“‹ package.json
โ”œโ”€โ”€ ๐Ÿ“ packages/
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ artifacts/
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ README.md
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“‹ package.json
โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ“ statics/
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ database/
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ README.md
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ data/
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“‹ package.json
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ src/
โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ“„ yarn.lock
โ”‚   โ””โ”€โ”€ ๐Ÿ“ shared/
โ”‚       โ”œโ”€โ”€ ๐Ÿ“œ IpcChannel.ts
โ”‚       โ””โ”€โ”€ ๐Ÿ“ config/
โ”œโ”€โ”€ ๐Ÿ“ resources/
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ cherry-studio/
โ”‚   โ”‚   โ”œโ”€โ”€ ๐ŸŒ license.html
โ”‚   โ”‚   โ””โ”€โ”€ ๐ŸŒ releases.html
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ data/
โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ“‹ agents.json
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ js/
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“œ bridge.js
โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ“œ utils.js
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ scripts/
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“œ download.js
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“œ install-bun.js
โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ“œ install-uv.js
โ”‚   โ””โ”€โ”€ ๐Ÿ“„ textMonitor.swift
โ”œโ”€โ”€ ๐Ÿ“ scripts/
โ”‚   โ”œโ”€โ”€ ๐Ÿ“œ after-pack.js
โ”‚   โ”œโ”€โ”€ ๐Ÿ“œ build-npm.js
โ”‚   โ”œโ”€โ”€ ๐Ÿ“œ check-i18n.js
โ”‚   โ”œโ”€โ”€ ๐Ÿ“œ check-i18n.ts
โ”‚   โ”œโ”€โ”€ ๐Ÿ“œ cloudflare-worker.js
โ”‚   โ”œโ”€โ”€ ๐Ÿ“œ notarize.js
โ”‚   โ”œโ”€โ”€ ๐Ÿ“œ remove-locales.js
โ”‚   โ”œโ”€โ”€ ๐Ÿ“œ replace-spaces.js
โ”‚   โ”œโ”€โ”€ ๐Ÿ“œ update-i18n.ts
โ”‚   โ”œโ”€โ”€ ๐Ÿ“œ utils.js
โ”‚   โ””โ”€โ”€ ๐Ÿ“œ version.js
โ”œโ”€โ”€ ๐Ÿ“ src/
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ components/
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ main/
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“œ config.ts
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“œ constant.ts
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“œ electron.d.ts
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ embeddings/
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“œ env.d.ts
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“œ index.ts
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ integration/
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“œ ipc.ts
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ loader/
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ mcpServers/
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ reranker/
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ services/
โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ“ utils/
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ preload/
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“œ index.d.ts
โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ“œ index.ts
โ”‚   โ””โ”€โ”€ ๐Ÿ“ renderer/
โ”‚       โ”œโ”€โ”€ ๐ŸŒ index.html
โ”‚       โ””โ”€โ”€ ๐Ÿ“ src/
โ”œโ”€โ”€ ๐Ÿ“‹ tsconfig.json
โ”œโ”€โ”€ ๐Ÿ“‹ tsconfig.node.json
โ”œโ”€โ”€ ๐Ÿ“‹ tsconfig.web.json
โ””โ”€โ”€ ๐Ÿ“„ yarn.lock
  1. Show file metadata with JSON output:
treex -sM -f json -o structure.json
  • -s: Show file sizes
  • -M: Show modification times
  • -f json: Output in JSON format
  • -o structure.json: Save to structure.json file
Result:
{
  "name": "./",
  "isDir": true,
  "depth": 0,
  "size": 4096,
  "modTime": "2024-01-15 10:30:00",
  "children": [
    {
      "name": "README.md",
      "isDir": false,
      "depth": 1,
      "size": 11764,
      "modTime": "2024-01-15 10:30:00"
    },
    {
      "name": "src",
      "isDir": true,
      "depth": 1,
      "size": 4096,
      "modTime": "2024-01-15 10:30:00",
      "children": [
        {
          "name": "main.go",
          "isDir": false,
          "depth": 2,
          "size": 3720,
          "modTime": "2024-01-15 10:30:00"
        }
      ]
    }
  ]
}

๐Ÿ“ To Do

  • Support config file, allow user to customize the default output format, filtering options, styles etc.
  • Better performance for large directory trees
  • Better way to show file/dir types
  • Streamline installation process for MacOS & Linux systems(help needed!)
  • And more! Tell me in issues if you have any ideas.

โ™ฅ๏ธ Contribution

The project is in its early stages of development. All contributions are welcome, including raising issues, submitting pull requests, or giving the project a โญ star on GitHub!

โญ Star History

Star History Chart

About

๐ŸŒณโŒ: Treex is a CLI for directory structure visualization in various formats with powerful filters.

Topics

Resources

License

Stars

Watchers

Forks

Languages