Compare commits

...

2 Commits

Author SHA1 Message Date
Timon Ringwald
51c6ca56ac moved to git.milar.in 2022-08-03 21:29:55 +02:00
Timon Ringwald
8eb4c0d173 sort files based on size 2022-08-03 21:28:50 +02:00
5 changed files with 21 additions and 18 deletions

View File

@ -141,13 +141,6 @@ func (e *DirectoryEntry) SetRemovalMark(mark bool) {
for _, entry := range e.Entries() { for _, entry := range e.Entries() {
entry.SetRemovalMark(mark) 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 { func (e *DirectoryEntry) RemovalMark() bool {
@ -166,6 +159,12 @@ func (e *DirectoryEntry) modifySize(modifier uint64) {
*e.modSize += modifier *e.modSize += modifier
if e.parent != nil { if e.parent != nil {
e.parent.modifySize(modifier) 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()
})
} }
} }

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
"sort"
"strings" "strings"
) )
@ -117,6 +118,12 @@ func (e *FileEntry) SetRemovalMark(mark bool) {
} else { } else {
e.modifySize(*e.size) 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 { func (e *FileEntry) RemovalMark() bool {

8
go.mod
View File

@ -1,15 +1,11 @@
module git.tordarus.net/Tordarus/diskspace module git.milar.in/milarin/diskspace
go 1.18 go 1.18
require ( require github.com/fatih/color v1.13.0
github.com/fatih/color v1.13.0
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d
)
require ( require (
github.com/mattn/go-colorable v0.1.9 // indirect github.com/mattn/go-colorable v0.1.9 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect github.com/mattn/go-isatty v0.0.14 // indirect
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 // indirect
) )

5
go.sum
View File

@ -5,12 +5,7 @@ github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d h1:sK3txAijHtOK88l68nt020reeT1ZdKLIYetKl95FzVY=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=

View File

@ -26,6 +26,12 @@ var (
IconTheme = flag.String("i", "unicode", "icon theme (currently supported: default, unicode, nerd)") 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() { func main() {
flag.Parse() flag.Parse()
rootPath := flag.Arg(0) rootPath := flag.Arg(0)