From 2345e1679453a80f42bce3bf910b2cb53ed081cc Mon Sep 17 00:00:00 2001 From: Ivan Menshykov Date: Tue, 18 Oct 2016 22:17:27 +0200 Subject: [PATCH] Dirfirst option and numerical sorting (#27) * Create option dirfirst, and add numerical sorting * Add only dirfirst option --- comp.go | 3 +++ doc.go | 1 + docstring.go | 1 + eval.go | 9 +++++++++ nav.go | 6 ++++-- opts.go | 2 ++ 6 files changed, 20 insertions(+), 2 deletions(-) diff --git a/comp.go b/comp.go index 6195a6f..186e99c 100644 --- a/comp.go +++ b/comp.go @@ -49,6 +49,9 @@ var ( "preview", "nopreview", "preview!", + "dirfirst", + "nodirfirst", + "dirfirst!", "scrolloff", "tabstop", "ifs", diff --git a/doc.go b/doc.go index d3d91d9..0fc8414 100644 --- a/doc.go +++ b/doc.go @@ -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) diff --git a/docstring.go b/docstring.go index fa7c556..11dad52 100644 --- a/docstring.go +++ b/docstring.go @@ -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) diff --git a/eval.go b/eval.go index 27a473b..2f66815 100644 --- a/eval.go +++ b/eval.go @@ -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 { diff --git a/nav.go b/nav.go index d0c928b..a0fca04 100644 --- a/nav.go +++ b/nav.go @@ -107,9 +107,11 @@ func organizeFiles(fi []os.FileInfo) []os.FileInfo { 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(ByDir(fi)) return fi } diff --git a/opts.go b/opts.go index 7532d09..2615836 100644 --- a/opts.go +++ b/opts.go @@ -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)