Dirfirst option and numerical sorting (#27)

* Create option dirfirst, and add numerical sorting

* Add only dirfirst option
This commit is contained in:
Ivan Menshykov 2016-10-18 22:17:27 +02:00 committed by gokcehan
parent d36e272272
commit 2345e16794
6 changed files with 20 additions and 2 deletions

View File

@ -49,6 +49,9 @@ var (
"preview",
"nopreview",
"preview!",
"dirfirst",
"nodirfirst",
"dirfirst!",
"scrolloff",
"tabstop",
"ifs",

1
doc.go
View File

@ -46,6 +46,7 @@ The following options can be used to customize the behavior of lf.
hidden bool (default off)
preview bool (default on)
dirfirst bool (default on)
scrolloff int (default 0)
tabstop int (default 8)
ifs string (default "") (not exported if empty)

View File

@ -50,6 +50,7 @@ The following options can be used to customize the behavior of lf.
hidden bool (default off)
preview bool (default on)
dirfirst bool (default on)
scrolloff int (default 0)
tabstop int (default 8)
ifs string (default "") (not exported if empty)

View File

@ -26,6 +26,15 @@ func (e *SetExpr) eval(app *App, args []string) {
gOpts.preview = false
case "preview!":
gOpts.preview = !gOpts.preview
case "dirfirst":
gOpts.dirfirst = true
app.nav.renew(app.nav.height)
case "nodirfirst":
gOpts.dirfirst = false
app.nav.renew(app.nav.height)
case "dirfirst!":
gOpts.dirfirst = !gOpts.dirfirst
app.nav.renew(app.nav.height)
case "scrolloff":
n, err := strconv.Atoi(e.val)
if err != nil {

6
nav.go
View File

@ -107,9 +107,11 @@ func organizeFiles(fi []os.FileInfo) []os.FileInfo {
log.Printf("unknown sorting type: %s", gOpts.sortby)
}
// TODO: these should be optional
sort.Stable(ByNum(fi))
if gOpts.dirfirst {
sort.Stable(ByDir(fi))
}
//TODO this should be optional
sort.Stable(ByNum(fi))
return fi
}

View File

@ -10,6 +10,7 @@ var gOpts struct {
shell string
showinfo string
sortby string
dirfirst bool
ratios []int
keys map[string]Expr
cmds map[string]Expr
@ -23,6 +24,7 @@ func init() {
gOpts.shell = envShell
gOpts.showinfo = "none"
gOpts.sortby = "name"
gOpts.dirfirst = true
gOpts.ratios = []int{1, 2, 3}
gOpts.keys = make(map[string]Expr)