Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jez/as-tree-cpp
Print a list of paths as a tree of paths 🌳
https://github.com/jez/as-tree-cpp
cli
Last synced: 3 days ago
JSON representation
Print a list of paths as a tree of paths 🌳
- Host: GitHub
- URL: https://github.com/jez/as-tree-cpp
- Owner: jez
- License: other
- Created: 2020-05-10T03:29:56.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-05-11T15:30:43.000Z (over 4 years ago)
- Last Synced: 2024-10-25T14:57:36.559Z (16 days ago)
- Topics: cli
- Language: Starlark
- Homepage:
- Size: 123 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# as-tree-cpp
**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](https://github.com/sharkdp/fd/issues/283).
## Install
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.```shell
# 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
```## Usage
```
❯ as-tree --help
Print a list of paths as a tree of paths.Usage:
as-tree []Arguments:
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
```shell
# 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
```## TODO(jez)
- 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`
- [ ] Collapse consecutive singleton tries into one level
- `tree` also does this