Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jez/as-tree
Print a list of paths as a tree of paths 🌳
https://github.com/jez/as-tree
cli
Last synced: about 13 hours ago
JSON representation
Print a list of paths as a tree of paths 🌳
- Host: GitHub
- URL: https://github.com/jez/as-tree
- Owner: jez
- License: other
- Created: 2020-05-11T02:47:12.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-10-07T12:59:11.000Z (over 3 years ago)
- Last Synced: 2025-01-04T21:12:13.851Z (8 days ago)
- Topics: cli
- Language: Rust
- Homepage:
- Size: 163 KB
- Stars: 467
- Watchers: 8
- Forks: 20
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-list - as-tree
- jimsghstars - jez/as-tree - Print a list of paths as a tree of paths 🌳 (Rust)
README
# as-tree
[![Build Status](https://travis-ci.org/jez/as-tree.svg?branch=master)](https://travis-ci.org/jez/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 controlling which files to list.Inspired by [this feature request](https://github.com/sharkdp/fd/issues/283).
## 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:
```shell
cargo install -f --git https://github.com/jez/as-tree
```To install from source using Bazel:
```shell
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 [options] []Arguments:
The file to read from. When omitted, reads from stdin.Options:
--color (always|auto|never)
Whether to colorize the output [default: auto]
-f Prints the full path prefix for each file.
-h, --help Print this help messageExample:
find . -name '*.txt' | as-tree
```## 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).```shell
# 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
- [ ] Only use box drawing characters if the locale supports it
- See `man locale`, `LC_CTYPE=C tree`
- [ ] Add a `-0` flag to support files with newlines in their name
- Seriously why is this allowed?