Implement directory count info (#85)
This commit is contained in:
parent
9962b378a8
commit
fe05105c88
3
comp.go
3
comp.go
@ -47,6 +47,9 @@ var (
|
||||
}
|
||||
|
||||
gOptWords = []string{
|
||||
"dircounts",
|
||||
"nodircounts",
|
||||
"dircounts!",
|
||||
"dirfirst",
|
||||
"nodirfirst",
|
||||
"dirfirst!",
|
||||
|
1
doc.go
1
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)
|
||||
|
@ -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)
|
||||
|
6
eval.go
6
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)
|
||||
|
2
nav.go
2
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
|
||||
|
2
opts.go
2
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
|
||||
|
24
ui.go
24
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:
|
||||
|
Loading…
Reference in New Issue
Block a user