From 8eb4c0d1738010c69eb04eef07161331c88a3903 Mon Sep 17 00:00:00 2001 From: Timon Ringwald Date: Wed, 3 Aug 2022 21:28:45 +0200 Subject: [PATCH] sort files based on size --- dir_entry.go | 13 ++++++------- file_entry.go | 7 +++++++ main.go | 6 ++++++ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/dir_entry.go b/dir_entry.go index 59fbcac..e693f86 100644 --- a/dir_entry.go +++ b/dir_entry.go @@ -141,13 +141,6 @@ func (e *DirectoryEntry) SetRemovalMark(mark bool) { for _, entry := range e.Entries() { entry.SetRemovalMark(mark) } - - if e.Parent() != nil { - pentries := e.Parent().Entries() - sort.Slice(pentries, func(i, j int) bool { - return pentries[i].SizeModified() < pentries[j].SizeModified() - }) - } } func (e *DirectoryEntry) RemovalMark() bool { @@ -166,6 +159,12 @@ func (e *DirectoryEntry) modifySize(modifier uint64) { *e.modSize += modifier if e.parent != nil { e.parent.modifySize(modifier) + + // recalculate order of parent entries + pentries := e.Parent().Entries() + sort.Slice(pentries, func(i, j int) bool { + return pentries[i].SizeModified() < pentries[j].SizeModified() + }) } } diff --git a/file_entry.go b/file_entry.go index b749b53..95bf23a 100644 --- a/file_entry.go +++ b/file_entry.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "path/filepath" + "sort" "strings" ) @@ -117,6 +118,12 @@ func (e *FileEntry) SetRemovalMark(mark bool) { } else { e.modifySize(*e.size) } + + // recalculate order of parent entries + pentries := e.Parent().Entries() + sort.Slice(pentries, func(i, j int) bool { + return pentries[i].SizeModified() < pentries[j].SizeModified() + }) } func (e *FileEntry) RemovalMark() bool { diff --git a/main.go b/main.go index 6209a62..3d8d7ac 100644 --- a/main.go +++ b/main.go @@ -26,6 +26,12 @@ var ( IconTheme = flag.String("i", "unicode", "icon theme (currently supported: default, unicode, nerd)") ) +// FIXME sometimes sorting not applied after removing items +// TODO pwd command showing Current entry path and Root entry path in filesystem +// TODO arrow up -> last command (`stty -raw` necessary?). even better: rlwrap impl (see tsoding noq) +// TODO config file with preferred icon theme or read best icon theme from terminfo somehow +// TODO on exit: show deleted files in recursive tree (only deleted files and their parent directories) +// TODO autocomplete on TAB (see arrow up issue: raw necessary?) func main() { flag.Parse() rootPath := flag.Arg(0)