Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: add --tree flag #283

Closed
skyegecko opened this issue Apr 13, 2018 · 9 comments
Closed

Request: add --tree flag #283

skyegecko opened this issue Apr 13, 2018 · 9 comments

Comments

@skyegecko
Copy link

Would it be possible to include a --tree flag which produces output similar to tree? I saw this was briefly mentioned in #107, but the issue was actually about something else.

@sharkdp
Copy link
Owner

sharkdp commented Apr 13, 2018

Thank you for your feedback.

Would it be possible to include a --tree flag which produces output similar to tree?

Why do you want this to be included? Do you see a strong use case for this?

It would certainly be possible somehow, but:

  • 'fd' searches the file system in a parallel, non-systematic way. Rendering a tree-like output would therefore require us to collect all results first before we could print anything.
  • This would be a rather big feature. It would require large-scale changes to the code base. All these changes would have to be maintained in the future.
  • Interactions with all kinds of other command line options (--absolute-path, --follow, --print0...) would have to be investigated.

Overall, to be honest, I don't feel like this would be worth the effort.

Maybe a second program could help here. I tried to use fd .. | xargs with tree and exa --tree, but didn't get this to work.

@sharkdp sharkdp added the idea label Apr 13, 2018
@skyegecko
Copy link
Author

skyegecko commented Apr 14, 2018

The appeal to me is simply that it's nicer to view when there is a large number of results in multiple subdirectories. If it requires a large overhaul to existing code though then it sounds like a poor fit. I'll see if some concoction of shell scripting can produce the desired output.

@sharkdp
Copy link
Owner

sharkdp commented Apr 26, 2018

Unfortunately, I think this is out of the scope for fd and could better be handled by a second, external program. I'm going to close this for now.

@sharkdp sharkdp closed this as completed Apr 26, 2018
@jez
Copy link
Contributor

jez commented May 11, 2020

👋 I built the suggested external program:

https://github.com/jez/as-tree

Screen Shot 2020-05-10 at 10 54 21 PM

@sharkdp
Copy link
Owner

sharkdp commented May 12, 2020

wave I build the suggested external program:

Very cool! Thanks for posting this here. If you want to add LS_COLORS support, you could use my lscolors crate as a library.

Note that there are some weird edge-cases (like filenames including newline-characters) which would not work when simply piping to as-tree. If you want to handle those, you could either add a -0 option (similar to xargs, find and fd) which would read \0-separated filenames instead of \n-separated ones.

Alternatively, you could also accept paths as arguments and use fd … -X as-tree instead of fd … | as-tree. This should also work with weird filenames. This would suffer from command-line argument length restrictions (see also: #410).

@sharkdp
Copy link
Owner

sharkdp commented May 12, 2020

If you like, we could add a section to the README: https://github.com/sharkdp/fd#integration-with-other-programs

@jez
Copy link
Contributor

jez commented May 12, 2020

If you want to add LS_COLORS support, you could use my lscolors crate as a library.

https://github.com/jez/as-tree/compare/jez-lscolors

^ I actually was working on that last night. I was meaning to say: it's a wonderful library! I'm so glad it exists. Simple to use and worked exactly as expected. Thanks for building it as a standalone library!

Note that there are some weird edge-cases

Thanks for the heads up, I'll consider adding a -0 flag or something.

If you like, we could add a section to the README

¯_(ツ)_/¯ I'm not opposed but I'd like to at least polish it a bit more if I were to add it there.

Thanks again, I'll keep you posted.

@sharkdp
Copy link
Owner

sharkdp commented May 12, 2020

Ah, cool - thank you for the feedback!

jez added a commit to jez/fd that referenced this issue May 13, 2020
sharkdp pushed a commit that referenced this issue May 13, 2020
Suggested in this comment:

    #283 (comment)
@dsifford
Copy link

dsifford commented Jul 6, 2021

Just an FYI @jez & @sharkdp: It's currently possible right now today to pipe the output of fd to tree as long as tree v1.8.0 is installed.

Example:

# note the output of fd first
$ fd .
dir1
dir1/child1
dir1/child1/foo.txt
dir2
dir2/bar.txt

# now note the output of the same command, but piped to tree using --fromfile
$ fd . | tree --fromfile .
.
├── dir1
│   └── child1
│       └── foo.txt
└── dir2
    └── bar.txt

3 directories, 2 files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants