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", "preview",
"nopreview", "nopreview",
"preview!", "preview!",
"dirfirst",
"nodirfirst",
"dirfirst!",
"scrolloff", "scrolloff",
"tabstop", "tabstop",
"ifs", "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) hidden bool (default off)
preview bool (default on) preview bool (default on)
dirfirst bool (default on)
scrolloff int (default 0) scrolloff int (default 0)
tabstop int (default 8) tabstop int (default 8)
ifs string (default "") (not exported if empty) 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) hidden bool (default off)
preview bool (default on) preview bool (default on)
dirfirst bool (default on)
scrolloff int (default 0) scrolloff int (default 0)
tabstop int (default 8) tabstop int (default 8)
ifs string (default "") (not exported if empty) ifs string (default "") (not exported if empty)

View File

@ -26,6 +26,15 @@ func (e *SetExpr) eval(app *App, args []string) {
gOpts.preview = false gOpts.preview = false
case "preview!": case "preview!":
gOpts.preview = !gOpts.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": case "scrolloff":
n, err := strconv.Atoi(e.val) n, err := strconv.Atoi(e.val)
if err != nil { 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) log.Printf("unknown sorting type: %s", gOpts.sortby)
} }
// TODO: these should be optional if gOpts.dirfirst {
sort.Stable(ByDir(fi))
}
//TODO this should be optional
sort.Stable(ByNum(fi)) sort.Stable(ByNum(fi))
sort.Stable(ByDir(fi))
return fi return fi
} }

View File

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