Skip to content
/ as-tree Public

Print a list of paths as a tree of paths 🌳

License

Notifications You must be signed in to change notification settings

jez/as-tree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

33 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

as-tree

Print a list of paths as a tree of paths.

For example, given:

dir1/foo.txt
dir1/bar.txt
dir2/qux.txt

it will print:

.
β”œβ”€β”€ dir1
β”‚   β”œβ”€β”€ foo.txt
β”‚   └── bar.txt
└── dir2
    └── qux.txt

This tool is particularly useful when used with find or fd to produce such a list of files. It's similar in spirit to tree, but find and fd tend to be more powerful when it comes to controling which files to list.

Inspired by this feature request.

Install

There are pre-built binary releases in the Releases tab.

This project is written in Rust and builds under both Bazel and Cargo.

To install from source using Cargo:

git clone https://github.com/jez/as-tree
cd as-tree
cargo install

To install from source using Bazel:

git clone https://github.com/jez/as-tree
cd as-tree
make install

Usage

❯ as-tree --help
Print a list of paths as a tree of paths.

Usage:
  as-tree [<file>]

Arguments:
  <file>      The file to read from [default: stdin]

Example

This tool is particularly useful with tools like fd which can prune the list of files to print better than tree can alone.

❯ fd --exclude test | as-tree
.
β”œβ”€β”€ LICENSE.md
β”œβ”€β”€ Makefile
β”œβ”€β”€ README.md
β”œβ”€β”€ WORKSPACE
β”œβ”€β”€ bazel
β”œβ”€β”€ main
β”‚   β”œβ”€β”€ BUILD
β”‚   └── main.cc
β”œβ”€β”€ third_party
β”‚   β”œβ”€β”€ BUILD
β”‚   β”œβ”€β”€ externals.bzl
β”‚   └── spdlog.BUILD
└── tools
    β”œβ”€β”€ BUILD
    β”œβ”€β”€ clang.bzl
    └── scripts
        β”œβ”€β”€ build_compilation_db.sh
        └── generate_compdb_targets.sh

Developing

Running the tests requires Bazel. The ./bazel shell script in this repo will download and cache a specific version of Bazel for you. From there, Bazel knows how to install all the dependencies it needs to build this project (including a Rust toolchain).

# Run the tests:
./bazel test --test_output=errors //test

# To add a test, create two files:
#
# - test/fixtures/foo.txt
# - test/fixtures/foo.txt.exp
#
# The first file is the input to feed to `as-tree`, and the second is the
# expected output of `as-tree` on that input

# Update all the tests:
./bazel test //test:update

# When you add a new dependency, you'll need to add it with Bazel too:
cargo install cargo-raze # (one time setup)
cd third_party/cargo
cargo raze

TODO(jez)

  • rustfmt / buildifier / shellcheck in CI
  • tests for CLI options
  • Only use box drawing characters if the locale supports it
    • See man locale, LC_CTYPE=C tree
  • Collapse consecutive singleton tries into one level
    • tree also does this