Coder Social home page Coder Social logo

as-tree's Introduction

as-tree

Build Status

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.

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:

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

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 [options] [<filename>]

Arguments:
  <filename>        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 message

Example:
  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).

# 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?

as-tree's People

Contributors

0xflotus avatar jez avatar raytracer avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.