As-tree - Print a list of paths as a tree of paths 🌳

Related tags

Command-line cli
Overview

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?
Comments
  • Support multiple input files

    Support multiple input files

    Hey @jez, I love this program, can you review this PR pls?

    I changed print! statements for write!(BufWriter, ...) for a small performance improvement.

    By doing some benchmarks using hyperfine, I saw improvements from 3% up to 8%, they were smaller than I expected, but I kept the changes anyway. image

    So yeah, I tried to improve at other parts but couldn't get better results.

    opened by marcospb19 4
  • added -f option to README and help text

    added -f option to README and help text

    Hi I just recently discovered this tool (via fd) and I think it works great! I just needed an option to display the full path like the -f option in tree does.

    opened by raytracer 3
  • Windows Support/Binary ?

    Windows Support/Binary ?

    Hi

    This is not an issue but just a query. I just recently came across this repository and was excited to test it. However, there doesn't appear to be any Windows binaries release I could take out for a spin. I briefly tried installing via rust/cargo but quickly ran into some errors. Is there support (or at least a plan) for Windows ?

    opened by chechu2k5 2
  • [CR]: remove token from .travis.yml?

    [CR]: remove token from .travis.yml?

    https://github.com/jez/as-tree/blob/01253c2e5c3c624802d2246967fce7d73ed1e044/.travis.yml#L24

    Is it a good idea to store this token in .travis.yml? Wouldn't it be better to use an environment variable which you can store on travis?

    opened by 0xflotus 2
  • Landing page built with Gitpages

    Landing page built with Gitpages

    Hey,

    I created this project a landing page using Gitpages, which you can watch here: https://twitter.com/gitpages/status/1415339126887522310

    Here is a demo of the page in action: https://www.gitpages.app/examples/as-tree.html

    Just wondered if you would like the page on the project or not?

    Up to you.

    You can find out how to use GitHub Pages to host the file if you wanted to: https://docs.gitpages.app/docs/guides/hosting#step-2---setup-github-pages

    Would love to know your thoughts or feedback!

    Cheers, Dave

    opened by boyney123 1
  • fmt::Display

    fmt::Display

    I saw you attempted this a few weeks ago?

    If you want you can take this and adapt it however you want.

    (ps: this is not meant to be merged, just to signal)

    opened by jRimbault 0
  • Add support for musl release package

    Add support for musl release package

    Hi,

    I have an old linux distribution that does not come with GLIBC_2.18. So the linux binaries archive does not work for me.

    Would it be possible to add a release target that either compiles with GLIBC statically? Or alternatively, a MUSL target, which seems to be a static build anyway, similar to ripgrep or fd ?

    opened by j-xella 0
  • Use any character als Directory separator

    Use any character als Directory separator

    I realy like the feature but it's strength would potentiate if you could use any character as an separator. If you would e.g. print out JSON as dot-separated string (https://github.com/tomnomnom/gron) you could than view the whole thing as an tree

    opened by HoffmannP 0
  • Option to group directories last

    Option to group directories last

    When finding paths with find and fd, I often pipe the results into a script I wrote called pathsort that groups files before directories.

    Piping the output of pathsort into as-tree has no effect, as as-tree sorts its input.

    It would be nice if as-tree had an option to group files before directories.

    Gnu ls has the --group-directories-first option. tree has the --dirsfirst option. A long flag like those would be fine, but a one letter short flag would be ideal. Neither has an option to group files first.

    For list output, I can see both groupings to be useful, but the existing tools only offer directories first.

    For find and tree output, for some reason grouping files before directories makes more sense to me. I'm not sure why. Maybe it's because once you've seen the files in the directory, you can be done thinking about that directory for the remainder of the output.

    This is my pathsort script:

    #!/bin/sh
    set -euo pipefail
    
    # 1.  Replace the last `/` with `/ /`
    # 2.  Sort
    # 3.  Replace the `/ /` with `/`
    pathsort()
    {
            sed -E 's/(.*)\//\1\/ \//' | sort | sed -E 's/(.*)\/ \//\1\//'
    }
    
    case "${1-}" in
            -fd )
                    # It would be nice if `fd` had an option to prepend `./` to all relative paths,
                    # so that all paths have at least one `/` in them.
                    sed 's/^/.\//' | pathsort
                    ;;
            * )
                    pathsort
                    ;;
    esac
    

    Off topic

    I have this in my shell's rc file:

    fdtree() { fd . -H -E .git "$@" | as-tree ; }
    

    I've been using fdtree more than tree lately because I can write fdtree -E aaa -E bbb to exclude using multiple patterns, while tree can only have one -I ignore pattern.

    Thanks for as-tree. I love it!

    opened by jzinn 3
  • Fix panic on broken pipes

    Fix panic on broken pipes

    Fixes a panic when writing to a closed pipe by explicitly ignoring this error type.

    This commit also changes the behavior of as-tree on empty inputs which would previously result in a (superfluous) newline.

    closes #15 closes #19

    opened by sharkdp 0
  • If piped output is empty can as-tree not print new line?

    If piped output is empty can as-tree not print new line?

    If fdfind folder_name returns a empty output | as-tree prints a new-line. Is it possible to not make it print new-line?

    Actual behavior:

    $ fdfind folder_name  # returns no solution
    $ fdfind folder_name | as-tree                                       
    
    $
    

    Wanted behavior:

    $ fdfind folder_name  # returns no solution
    $ fdfind folder_name | as-tree                                       
    $
    
    opened by avatar-lavventura 0
Owner
Jake Zimmerman
Working on @sorbet at Stripe.
Jake Zimmerman
An easy to use library for pretty print tables of Rust structs and enums.

tabled An easy to use library for pretty printing tables of Rust structs and enums. Table of Contents Usage Settings Style Themes ASCII Psql Github Ma

Maxim Zhiburt 1.3k Jan 9, 2023
Print your git contributions in your terminal, blazingly fast

Takoyaki Blazingly fast git contribution graph in your terminal Features ✔️ Customizable ✔️ Plugins to support a bunch of cloud based git repositories

kyeboard 13 Feb 6, 2023
Macro to print variable(s) with values nicely (stripped from release builds)

log_macro Macro to print variable(s) with values nicely (stripped from release builds) Install cargo add log_macro Use Add this to top of file: #[mac

Nikita 3 Aug 22, 2023
Download pdbs from symbol servers and cache locally, parse symbol paths from env vars

symsrv This crate lets you download and cache pdb files from symbol servers, according to the rules from the _NT_SYMBOL_PATH environment variable. It

Markus Stange 6 Sep 15, 2022
Temporary files and directories with UTF-8 paths.

camino-tempfile A secure, cross-platform, temporary file library for Rust with UTF-8 paths. This crate is a wrapper around tempfile that works with th

null 4 Apr 24, 2023
Count your code by tokens, types of syntax tree nodes, and patterns in the syntax tree. A tokei/scc/cloc alternative.

tcount (pronounced "tee-count") Count your code by tokens, types of syntax tree nodes, and patterns in the syntax tree. Quick Start Simply run tcount

Adam P. Regasz-Rethy 48 Dec 7, 2022
Traversal of tree-sitter Trees and any arbitrary tree with a TreeCursor-like interface

tree-sitter-traversal Traversal of tree-sitter Trees and any arbitrary tree with a TreeCursor-like interface. Using cursors, iteration over the tree c

Sebastian Mendez 12 Jan 8, 2023
belt is a command line app that can show your time from a list of selected time zones

A CLI app to show your time from a list of selected time zones, and a rust lib to parse dates in string formats that are commonly used.

Rollie Ma 23 Nov 4, 2022
A curated list of replacements for existing software written in Rust

Awesome Alternatives in Rust A curated list of replacements for existing software written in Rust. If you want to contribute, please read CONTRIBUTING

Takayuki Maeda 2.7k Jan 8, 2023
CLI app to display list of trending anime, music charts or recommend anime to watch or song to listen to.

Description Anitrendz is a cli app that uses data from the anitiop api to list the top anime and songs or recommend a random anime to watch or song to

Jimmy 9 Jun 11, 2022
Curated list of awesome projects and resources related to Rust and computer security

Awesome Rust Security Curated list of awesome projects and resources related to Rust and computer security Table of Contents Tools Web and Cloud Secur

Alan 131 Jan 1, 2023
argmax is a library that allows Rust applications to avoid Argument list too long errors (E2BIG) by providing a std::process::Command wrapper with a

argmax argmax is a library that allows Rust applications to avoid Argument list too long errors (E2BIG) by providing a std::process::Command wrapper w

David Peter 22 Nov 20, 2022
A command-line tool to generate a list of required missing Android OS Project blobs.

aosp-missing-blobs aosp-missing-blobs is a nifty tool to identify required blobs (.so) that are missing from AOSP ROM builds, and to show which existi

Josh 176 Dec 16, 2022
A list of crates with snippets used by me to learn more about Rust.

my-rust-examples This is a list of crates used by me to learn Rust. How to execute You can use a dependency called cargo-play: cargo install cargo-pla

Ronald 0 Jan 3, 2022
Cargo-about - 📜 Cargo plugin to generate list of all licenses for a crate 🦀

?? cargo-about Cargo plugin for generating a license listing for all dependencies of a crate See the book ?? for in-depth documentation. Please Note:

Embark 281 Jan 1, 2023
⚙️ A curated list of static analysis (SAST) tools for all programming languages, config files, build tools, and more.

This repository lists static analysis tools for all programming languages, build tools, config files and more. The official website, analysis-tools.de

Analysis Tools 10.7k Jan 2, 2023
List public items (public API) of library crates. Enables diffing public API between releases.

cargo-public-items List public items (the public API) of a Rust library crate by analyzing the rustdoc JSON of the crate. Automatically builds the rus

Martin Nordholts 203 Dec 31, 2022
CLI tool that extracts a regex pattern from a list of urls ( Rust )

rextract CLI tool that extracts a regex pattern from a list of urls. The tool is written in Rust and supports PCRE. Installation Step 1: Visit https:/

null 45 Dec 11, 2022
A todo list app that indexes your app to find TODO:'s

forgot A todo list app that indexes your app to find TODO:'s Usage to list all your todos forgot list list all your todos ignoring search in ./target,

null 2 Oct 6, 2022