dive icon indicating copy to clipboard operation
dive copied to clipboard

Order tree by size

Open ccinelli opened this issue 5 years ago • 21 comments

This is a great tool. Can you add an option to order the folder structure by size?

ccinelli avatar Nov 26 '18 18:11 ccinelli

@wagoodman I am picking up this, do let me know if you already started working on this :)

darxtrix avatar Nov 27 '18 15:11 darxtrix

@darxtrix haven't started yet, have at it!

wagoodman avatar Nov 27 '18 15:11 wagoodman

Cool, thanks will send in a PR when done.

darxtrix avatar Nov 27 '18 15:11 darxtrix

@wagoodman currently the file search is implemented at complete FileTree level and not at a particular FIleNode level, so are we going to implement the sorting operation on the FileTree level or FileNode level ? A FileTree level sort will be more resourcing consuming and I guess at a particular point users are mostly interested in sorting at a FileNode (directory).

darxtrix avatar Nov 27 '18 16:11 darxtrix

I took this issue to be sort the current directory in the tree by size, but what you're really saying is globally sort the tree contents by size, regardless of which directory it is in? If that's true, then this is a heavier lift since it implies replacing the filetree UI (right pane) entirely.

Since each directory is showing the aggregated content size, would sorting the dir contents be good enough? Later tonight I can jump back on and go into a bit more detail.

wagoodman avatar Nov 27 '18 20:11 wagoodman

Sorry for late reply. Timezone issues.

@wagoodman I was trying communicate the same as you mentioned. We should sort at the directory level instead of full tree level.

We might need to put some parameter representing the total size of the directory at the FileNode level otherwise we have to traverse down recursively each time. What are your thoughts on this ? Should we have to support both ASC or DESC sort, or the DESC is sufficient ?

darxtrix avatar Nov 28 '18 08:11 darxtrix

Hi @wagoodman, just following up. Any thoughts on this ?

darxtrix avatar Nov 30 '18 13:11 darxtrix

Sorry for the delay, you're right about needing to add a total size parameter on the FileNode struct... I'll call it branchSize here, or the total number of bytes on this tree branch --from this node and it's children. My first thought is to populate branchSize at either FileTree.AddPath or FileNode.AddChild. The upside is that this is the only place that we are affecting the tree structure. The downside is that there may be a performance hit when calling something like FileTree.StackRange.

The next problem to solve is ensuring that there is parity with rendering the tree string. Currently it presumes that each dir contents is sorted alphabetically (https://github.com/wagoodman/dive/blob/master/filetree/tree.go#L73), so now there will need to be a way to indicate the current sort preference and reference that here.

As for ASC/DESC, I'd start with DESC for now, we can always expand it to ASC later (this becomes more of a screen realestate problem than a technical problem... the bottom hint bar that shows keybinding hints is getting full).

wagoodman avatar Nov 30 '18 14:11 wagoodman

Cool, I will go ahead and implement this. Thanks !

darxtrix avatar Nov 30 '18 14:11 darxtrix

I see this issue was removed from "UI Enhancements". What is the status of this? Is it just low priority?

Thanks.

marshallford avatar Jun 29 '19 19:06 marshallford

@wagoodman Is this abandoned?

Sarke avatar Jun 30 '20 02:06 Sarke

It seems like this specific issue is probably up for grabs, yup.

wagoodman avatar Jun 30 '20 10:06 wagoodman

Would (still) be greatly appreciated in 2021 :) Love the tool 👍

Dunky13 avatar Jul 06 '21 12:07 Dunky13

+1

jkryanchou avatar Sep 14 '21 08:09 jkryanchou

+1, this would be super beneificial. Currently, I find myself going into an interactive terminal, and running something like du -sh node_modules/* | grep M to find anything that's at least a MB.

dlinning-jockey avatar Jan 07 '22 14:01 dlinning-jockey

I'll join the choir and say that this would be a terrific feature. Also, I would like to add that dive is a fantastic tool and I truly appreciate all the work you put in.

RasmusJohns avatar May 04 '22 08:05 RasmusJohns

Still would be a great feature in 2022 :)

avramdj avatar Jun 10 '22 00:06 avramdj

In 2023 we would also really appreciate if this is implemented

not-poma avatar Mar 14 '23 10:03 not-poma

looks like this was added in v0.11.0. If you're focused on the current layer contents pane and hit CTRL + o, it'll sort by size.

Eric-Tyrrell22 avatar Sep 05 '23 01:09 Eric-Tyrrell22

Awesome, we did it guys. (by bumping a feature request for half a decade and absolutely no one making a single PR). Another win for open source 😎

avramdj avatar Sep 05 '23 01:09 avramdj

FYI: This issue has been resolved by https://github.com/wagoodman/dive/pull/424

Potherca avatar Sep 10 '23 08:09 Potherca