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{
|
gOptWords = []string{
|
||||||
|
"dircounts",
|
||||||
|
"nodircounts",
|
||||||
|
"dircounts!",
|
||||||
"dirfirst",
|
"dirfirst",
|
||||||
"nodirfirst",
|
"nodirfirst",
|
||||||
"dirfirst!",
|
"dirfirst!",
|
||||||
|
1
doc.go
1
doc.go
@ -68,6 +68,7 @@ keybindings:
|
|||||||
|
|
||||||
The following options can be used to customize the behavior of lf:
|
The following options can be used to customize the behavior of lf:
|
||||||
|
|
||||||
|
dircounts boolean (default off)
|
||||||
dirfirst boolean (default on)
|
dirfirst boolean (default on)
|
||||||
hidden boolean (default off)
|
hidden boolean (default off)
|
||||||
preview boolean (default on)
|
preview boolean (default on)
|
||||||
|
@ -72,6 +72,7 @@ keybindings:
|
|||||||
|
|
||||||
The following options can be used to customize the behavior of lf:
|
The following options can be used to customize the behavior of lf:
|
||||||
|
|
||||||
|
dircounts boolean (default off)
|
||||||
dirfirst boolean (default on)
|
dirfirst boolean (default on)
|
||||||
hidden boolean (default off)
|
hidden boolean (default off)
|
||||||
preview boolean (default on)
|
preview boolean (default on)
|
||||||
|
6
eval.go
6
eval.go
@ -11,6 +11,12 @@ import (
|
|||||||
|
|
||||||
func (e *setExpr) eval(app *app, args []string) {
|
func (e *setExpr) eval(app *app, args []string) {
|
||||||
switch e.opt {
|
switch e.opt {
|
||||||
|
case "dircounts":
|
||||||
|
gOpts.dircounts = true
|
||||||
|
case "nodircounts":
|
||||||
|
gOpts.dircounts = false
|
||||||
|
case "dircounts!":
|
||||||
|
gOpts.dircounts = !gOpts.dircounts
|
||||||
case "dirfirst":
|
case "dirfirst":
|
||||||
gOpts.dirfirst = true
|
gOpts.dirfirst = true
|
||||||
app.nav.renew(app.nav.height)
|
app.nav.renew(app.nav.height)
|
||||||
|
2
nav.go
2
nav.go
@ -23,6 +23,7 @@ type file struct {
|
|||||||
os.FileInfo
|
os.FileInfo
|
||||||
LinkState linkState
|
LinkState linkState
|
||||||
Path string
|
Path string
|
||||||
|
Count int
|
||||||
}
|
}
|
||||||
|
|
||||||
type filesSortable struct {
|
type filesSortable struct {
|
||||||
@ -126,6 +127,7 @@ func readdir(path string) ([]*file, error) {
|
|||||||
FileInfo: lstat,
|
FileInfo: lstat,
|
||||||
LinkState: linkState,
|
LinkState: linkState,
|
||||||
Path: fpath,
|
Path: fpath,
|
||||||
|
Count: -1,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return fi, err
|
return fi, err
|
||||||
|
2
opts.go
2
opts.go
@ -3,6 +3,7 @@ package main
|
|||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
var gOpts struct {
|
var gOpts struct {
|
||||||
|
dircounts bool
|
||||||
dirfirst bool
|
dirfirst bool
|
||||||
hidden bool
|
hidden bool
|
||||||
preview bool
|
preview bool
|
||||||
@ -24,6 +25,7 @@ var gOpts struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
gOpts.dircounts = false
|
||||||
gOpts.dirfirst = true
|
gOpts.dirfirst = true
|
||||||
gOpts.hidden = false
|
gOpts.hidden = false
|
||||||
gOpts.preview = true
|
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 {
|
for _, s := range gOpts.info {
|
||||||
switch s {
|
switch s {
|
||||||
case "size":
|
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":
|
case "time":
|
||||||
info = fmt.Sprintf("%s %12s", info, f.ModTime().Format("Jan _2 15:04"))
|
info = fmt.Sprintf("%s %12s", info, f.ModTime().Format("Jan _2 15:04"))
|
||||||
default:
|
default:
|
||||||
|
Loading…
Reference in New Issue
Block a user