Git Product home page Git Product logo

as-tree-cpp's Introduction

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.

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.

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

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

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.