Note: I rewrote this in Rust because I was using a C++17 API that is only available on macOS Catalina and later:
https://github.com/jez/as-tree
This code still builds and passes the tests, but it will not be maintained.
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.
This project is written in C++ and built using Bazel. The Makefile will download all the tools you need to build it, including Bazel and a C++ toolchain.
# Build from source, installs to ~/.local/bin/as-tree
make install
# Build from source, installs to /usr/local/bin/as-tree
make install prefix=/usr/local
โฏ 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]
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
# Fast build (some debug info, but fast compile times):
./bazel build //main:as-tree
# Debug build (great debug info):
./bazel build //main:as-tree -c dbg --config=debugsymbols
# 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
# Launch the debugger:
lldb -- bazel-bin/main/as-tree
# Generate compile_commands.json for use with clangd (C++ LSP):
tools/scripts/build_compilation_db.sh
- Figure out how to support macOS older than Catalina
- clang-format / buildifier / shellcheck in CI
- tests for CLI options
- Color output according to LS_COLORS environment variable. Prior art:
- Only use box drawing characters if the locale supports it
- See
man locale
,LC_CTYPE=C tree
- See
- Collapse consecutive singleton tries into one level
tree
also does this