Skip to content

feat: add sort_by option to sort files by modification time #1040

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

Merged
merged 1 commit into from
Mar 3, 2022

Conversation

bdwiel
Copy link
Contributor

@bdwiel bdwiel commented Mar 2, 2022

Fixes #1039 for files only. I'll wait for feedback on whether you like this feature or not before investigating why it's not working on directories. I was thinking that directories will always be sorted above files at the same level. So for each node, show sorted(directories) followed by sorted(files/symlinks). What do you think?

@bdwiel bdwiel marked this pull request as draft March 3, 2022 15:46
@bdwiel bdwiel marked this pull request as ready for review March 3, 2022 16:13
@bdwiel
Copy link
Contributor Author

bdwiel commented Mar 3, 2022

I created separate functions for sorting by name or modification time. I also made it pull the modification time in the builders instead of the comparator. This looks cleaner and should ensure each node calls fs_stat just once :-)

Copy link
Member

@kyazdani42 kyazdani42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

almost good, some code smell.

Copy link
Member

@kyazdani42 kyazdani42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, nice feature. would be nice to add a toggle action for this too :)

@kyazdani42 kyazdani42 merged commit 690c7e9 into nvim-tree:master Mar 3, 2022
@siduck
Copy link
Contributor

siduck commented Sep 16, 2022

@kyazdani42
sort_by = "modification_time"

This option sorts by the last modified files. I want the opposite, is there any option for it? like showing last modified files/dirs at the end

So files/dirs which were created first will be shown first and the latest files/dirs at last.

sort_by = "modified_time_new" or "modified_time_old"

There could be two options for this ( the modified_time_new is the current one )

@alex-courtis
Copy link
Member

sort_by = "modified_time_new" or "modified_time_old"

That's pretty specific. We could be more generic with something like sort_reverse = false. Please raise a feature request.

@siduck
Copy link
Contributor

siduck commented Sep 19, 2022

sort_by = "modified_time_new" or "modified_time_old"

That's pretty specific. We could be more generic with something like sort_reverse = false. Please raise a feature request.

i doubt if sort_reverse would be helpful for other sort options like sort by name, extension etc

The current modification_time can be renamed to modified_time_new and a new sort option could be added modified_time_old ( old files on top )

or new_files , old_files

@alex-courtis
Copy link
Member

i doubt if sort_reverse would be helpful for other sort options like sort by name, extension etc

The current modification_time can be renamed to modified_time_new and a new sort option could be added modified_time_old ( old files on top )

or new_files , old_files

Please raise a feature request, with a PR gratefully appreciated.

sort_reverse may not make sense for the current options (although it does work) however can be used for future sort options.

Almo7aya pushed a commit to Almo7aya/nvim-tree.lua that referenced this pull request Oct 11, 2022
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

Successfully merging this pull request may close these issues.

Change the sort order
4 participants