diff --git a/comp.go b/comp.go index 4340a67..fc5c67c 100644 --- a/comp.go +++ b/comp.go @@ -47,6 +47,9 @@ var ( } gOptWords = []string{ + "dircounts", + "nodircounts", + "dircounts!", "dirfirst", "nodirfirst", "dirfirst!", diff --git a/doc.go b/doc.go index 48f7281..489d39c 100644 --- a/doc.go +++ b/doc.go @@ -68,6 +68,7 @@ keybindings: The following options can be used to customize the behavior of lf: + dircounts boolean (default off) dirfirst boolean (default on) hidden boolean (default off) preview boolean (default on) diff --git a/docstring.go b/docstring.go index bc95425..e23c396 100644 --- a/docstring.go +++ b/docstring.go @@ -72,6 +72,7 @@ keybindings: The following options can be used to customize the behavior of lf: + dircounts boolean (default off) dirfirst boolean (default on) hidden boolean (default off) preview boolean (default on) diff --git a/eval.go b/eval.go index d492405..11cc69b 100644 --- a/eval.go +++ b/eval.go @@ -11,6 +11,12 @@ import ( func (e *setExpr) eval(app *app, args []string) { switch e.opt { + case "dircounts": + gOpts.dircounts = true + case "nodircounts": + gOpts.dircounts = false + case "dircounts!": + gOpts.dircounts = !gOpts.dircounts case "dirfirst": gOpts.dirfirst = true app.nav.renew(app.nav.height) diff --git a/nav.go b/nav.go index 1bc6423..e0003ab 100644 --- a/nav.go +++ b/nav.go @@ -23,6 +23,7 @@ type file struct { os.FileInfo LinkState linkState Path string + Count int } type filesSortable struct { @@ -126,6 +127,7 @@ func readdir(path string) ([]*file, error) { FileInfo: lstat, LinkState: linkState, Path: fpath, + Count: -1, }) } return fi, err diff --git a/opts.go b/opts.go index 8c08e57..c2397bb 100644 --- a/opts.go +++ b/opts.go @@ -3,6 +3,7 @@ package main import "time" var gOpts struct { + dircounts bool dirfirst bool hidden bool preview bool @@ -24,6 +25,7 @@ var gOpts struct { } func init() { + gOpts.dircounts = false gOpts.dirfirst = true gOpts.hidden = false gOpts.preview = true diff --git a/ui.go b/ui.go index d00d3a6..6f6e027 100644 --- a/ui.go +++ b/ui.go @@ -291,7 +291,29 @@ func (win *win) printd(dir *dir, marks map[string]int, saves map[string]bool) { for _, s := range gOpts.info { switch s { case "size": - info = fmt.Sprintf("%s %4s", info, humanize(f.Size())) + if !(gOpts.dircounts && f.IsDir()) { + info = fmt.Sprintf("%s %4s", info, humanize(f.Size())) + continue + } + + if f.Count == -1 { + d, err := os.Open(path) + if err != nil { + log.Printf("opening dir to read count: %s", err) + continue + } + + names, err := d.Readdirnames(-1) + d.Close() + + if err != nil { + log.Printf("reading dir count: %s", err) + continue + } + + f.Count = len(names) + } + info = fmt.Sprintf("%s %d", info, f.Count) case "time": info = fmt.Sprintf("%s %12s", info, f.ModTime().Format("Jan _2 15:04")) default: