Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
G

gtree

> 包管理
Open source

Easily output ASCII tree from Go program or Markdown unordered list . There's also CLI tool that can output tree from JSON, YAML, or TOML! It's called *xtree*.

357 stars0 likes1 views
WebsiteGitHub

About

Easily output ASCII tree from Go program or Markdown unordered list . There's also CLI tool that can output tree from JSON, YAML, or TOML! It's called *xtree*.

[^1]

Easily output ASCII tree from Go program or Markdown unordered list (and it does more than just output tree!)

There's also a CLI tool that can output a tree from JSON, YAML, or TOML! It's called xtree.

Table of Contents

  • Features
    • Package - Programmable tree structure
      • Recommended for developers!
      • Acknowledgments
    • Package - Markdown to tree structure
    • Web
      • Generate ASCII tree from unordered Markdown list in Web UI (with editable branches).
    • CLI - gtree
      • Generate ASCII tree or directory from Markdown unordered list.
    • CLI - xtree
      • Generate ASCII tree from JSON/YAML/TOML.
  • Documents
  • Process
  • Performance
  • Contributing
  • Test coverage

Package - Programmable tree structure

[!NOTE] There are sample repositories that use gtree package.

See here for details.

Simple example

I urge you to run this program. This package is probably the easiest Go package to output tree.

…

Installation

Go version requires 1.24 or later.

bash
$ go get github.com/ddddddO/gtree

Usage

Function Description Available optional functions
OutputFromRoot can output tree WithMidBranch
WithLastBranch
WithVLine
WithHLine
WithEncodeJSON
WithEncodeTOML
WithEncodeYAML
MkdirFromRoot can create directories WithTargetDir
WithFileExtensions
WithDryRun
VerifyFromRoot can output the difference between tree you composed and directories WithTargetDir
WithStrictVerify
WalkFromRoot can execute user-defined function while traversing tree structure recursively WithMidBranch
WithLastBranch
WithVLine
WithHLine
WalkIterFromRoot it returns each node resulting from a recursive traversal of the tree structure, so you can process on each node WithMidBranch
WithLastBranch
WithVLine
WithHLine

[!TIP] Specifying WithDuplicationAllowed function in NewRoot function, which generates the Node arguments for the above functions, allows multiple nodes with the same text to exist within the same hierarchy.

Standard Pattern and Pattern Allowing Node Duplication

…

Acknowledgments

Thanks for providing very useful CLI for cloud storage tree output

Everyone is encouraged to use them!

⭐orangekame3/stree

CLI for Amazon S3 tree output. aws s3 command does not do what tree command does, but stree command can display tree!

⭐owlinux1000/gcstree

CLI for Google Cloud Storage tree output. gcloud storage command does not do what tree command does, but gcstree command can display tree!

gtree packeage has been utilized for other tools as well

I hope you will use these tools as well!

  • Tools

Package - Markdown to tree structure

Installation

Go version requires 1.24 or later.

bash
$ go get github.com/ddddddO/gtree

Usage

The symbols that can be used in Markdown are *, -, +, and #.

Function Description Available optional functions
OutputFromMarkdown can output trees WithMidBranch
WithLastBranch
WithVLine
WithHLine
WithEncodeJSON
WithEncodeTOML
WithEncodeYAML
WithMassive
MkdirFromMarkdown can create directories WithTargetDir
WithFileExtensions
WithDryRun
WithMassive
VerifyFromMarkdown can output the difference between markdown and directories WithTargetDir
WithStrictVerify
WithMassive
WalkFromMarkdown can execute user-defined function while traversing tree structure recursively WithMidBranch
WithLastBranch
WithVLine
WithHLine
WithMassive

Web

https://ddddddo.github.io/gtree/

This page is that converts from Markdown to tree!

This page calls a function that outputs tree. This function is a Go package compiled as WebAssembly.

The symbols that can be used in Markdown are *, -, +, and #.

Indentation represents hierarchy. The indentation can be whatever you specify, but use the same pattern.

You can change the branches like in the image below.

Also, once loaded, you can enjoy offline!

You can open it in your browser with

bash
$ gtree web

source code

CLI

gtree

Installation

Go $ go install github.com/ddddddO/gtree/cmd/gtree@latest

aqua $ aqua g -i ddddddO/gtree

Homebrew $ brew install gtree

Nix $ nix-env -i gtree or $ nix-shell -p gtree

MacPorts $ port install gtree

AUR $ wip...

Scoop $ scoop bucket add ddddddO https://github.com/ddddddO/scoop-bucket.git $ scoop install ddddddO/gtree

deb $ export GTREE_VERSION=X.X.X $ curl -o gtree.deb -L https://github.com/ddddddO/gtree/releases/download/v$GTREE_VERSION/gtree_$GTREE_VERSION-1_amd64.deb $ dpkg -i gtree.deb

rpm $ export GTREE_VERSION=X.X.X $ yum install https://github.com/ddddddO/gtree/releases/download/v$GTREE_VERSION/gtree_$GTREE_VERSION-1_amd64.rpm

apk $ export GTREE_VERSION=X.X.X $ curl -o gtree.apk -L https://github.com/ddddddO/gtree/releases/download/v$GTREE_VERSION/gtree_$GTREE_VERSION-1_amd64.apk $ apk add --allow-untrusted gtree.apk

Docker $ docker pull ghcr.io/ddddddo/gtree:latest $ docker run ghcr.io/ddddddo/gtree:latest template | docker run -i ghcr.io/ddddddo/gtree:latest output gtree ├── cmd │ └── gtree │ └── main.go ├── testdata │ ├── sample1.md │ └── sample2.md ├── Makefile └── tree.go

etc

download binary from here.

Usage

…

Output subcommand

…
Try it!
bash
$ gtree template
- gtree
        - cmd
                - gtree
                        - main.go
        - testdata
                - sample1.md
                - sample2.md
        - Makefile
        - tree.go
$ gtree template | gtree output
gtree
├── cmd
│   └── gtree
│       └── main.go
├── testdata
│   ├── sample1.md
│   └── sample2.md
├── Makefile
└── tree.go

Other pattern.

├── gtree output -f testdata/sample1.md
├── cat testdata/sample1.md | gtree output -f -
└── cat testdata/sample1.md | gtree output
Usage other than representing a directory.
bash
$ cat testdata/sample2.md | gtree output
k8s_resources
├── (Tier3)
│   └── (Tier2)
│       └── (Tier1)
│           └── (Tier0)
├── Deployment
│   └── ReplicaSet
│       └── Pod
│           └── container(s)
├── CronJob
│   └── Job
│       └── Pod
│           └── container(s)
└── (empty)
    ├── DaemonSet
    │   └── Pod
    │       └── container(s)
    └── StatefulSet
        └── Pod
            └── container(s)
Multiple roots
bash
$ cat testdata/sample6.md | gtree output
Artiodactyla
├── Artiofabula
│   ├── Cetruminantia
│   │   ├── Whippomorpha
│   │   │   ├── Hippopotamidae
│   │   │   └── Cetacea
│   │   └── Ruminantia
│   └── Suina
└── Tylopoda
Carnivora
├── Feliformia
└── Caniformia
    ├── Canidae
    └── Arctoidea
        ├── Ursidae
        └── x
            ├── Pinnipedia
            └── Musteloidea
                ├── Ailuridae
                └── x
                    ├── Mephitidae
                    └── x
                        ├── Procyonidae
                        └── Mustelidae
Output JSON

see

…
Output YAML

see

bash
$ cat testdata/sample5.md | gtree output --format yaml
value: a
children:
- value: i
  children:
  - value: u
    children:
    - value: k
      children: []
    - value: kk
      children: []
  - value: t
    children: []
- value: e
  children:
  - value: o
    children: []
- value: g
  children: []
Output TOML

see

bash
$ cat testdata/sample5.md | gtree output --format toml
value = 'a'
[[children]]
value = 'i'
[[children.children]]
value = 'u'
[[children.children.children]]
value = 'k'
children = []
[[children.children.children]]
value = 'kk'
children = []

[[children.children]]
value = 't'
children = []

[[children]]
value = 'e'
[[children.children]]
value = 'o'
children = []

[[children]]
value = 'g'
children = []

Mkdir subcommand

…
Try it!
bash
$ gtree template
- gtree
        - cmd
                - gtree
                        - main.go
        - testdata
                - sample1.md
                - sample2.md
        - Makefile
        - tree.go
$ gtree template | gtree mkdir
$ tree gtree/
gtree/
├── cmd
│   └── gtree
│       └── main.go
├── Makefile
├── testdata
│   ├── sample1.md
│   └── sample2.md
└── tree.go

8 directories, 0 files
make directories and files
bash
$ gtree template
- gtree
        - cmd
                - gtree
                        - main.go
        - testdata
                - sample1.md
                - sample2.md
        - Makefile
        - tree.go
$ gtree template | gtree mkdir -e .go -e .md -e Makefile
$ tree gtree/
gtree/
├── cmd
│   └── gtree
│       └── main.go
├── Makefile
├── testdata
│   ├── sample1.md
│   └── sample2.md
└── tree.go

3 directories, 5 files
dry run

Does not create a file and directory.

bash
$ gtree template | gtree mkdir --dry-run -e .go -e .md -e Makefile
gtree
├── cmd
│   └── gtree
│       └── main.go
├── testdata
│   ├── sample1.md
│   └── sample2.md
├── Makefile
└── tree.go

4 directories, 5 files

Any invalid file or directory name will result in an error.

bash
$ gtree mkdir --dry-run 
├── name
│   └── Alice
├── roles
│   ├── [0]
│   │   └── admin
│   └── [1]
│       └── editor
└── settings
    ├── notifications
    │   └── true
    └── theme
        └── dark

TOML to tree

…

YAML to tree

…

Omit index flg

bash
$ cat a.json | xtree output --omit-index
.
├── age
│   └── 30
├── devices
│   ├── os
│   │   ├── ios
│   │   └── windows
│   └── type
│       ├── mobile
│       └── desktop
├── height
│   └── 175.5
├── is_active
│   └── true
├── metadata
│   └── 
├── name
│   └── Alice
├── roles
│   ├── admin
│   └── editor
└── settings
    ├── notifications
    │   └── true
    └── theme
        └── dark

Level flg

bash
$ cat a.json | xtree output --level 1
.
├── age
├── devices
├── height
├── is_active
├── metadata
├── name
├── roles
└── settings

$ cat a.json | xtree output --level 2 --omit-index
.
├── age
│   └── 30
├── devices
│   ├── os
│   └── type
├── height
│   └── 175.5
├── is_active
│   └── true
├── metadata
│   └── 
├── name
│   └── Alice
├── roles
│

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Goclidirectorygogo-package

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category包管理
PricingOpen source

> Related tools

N
npm
Node.js 默认包管理器
P
pnpm
高效节省磁盘的 Node 包管理器
I
is-gif
Check if a Buffer/Uint8Array is a GIF image