diff --git a/comp.go b/comp.go index f2b1400..7c02fe6 100644 --- a/comp.go +++ b/comp.go @@ -56,6 +56,9 @@ var ( "preview", "nopreview", "preview!", + "reverse", + "noreverse", + "reverse!", "scrolloff", "tabstop", "filesep", diff --git a/doc.go b/doc.go index 812d1de..d538a97 100644 --- a/doc.go +++ b/doc.go @@ -51,6 +51,7 @@ The following options can be used to customize the behavior of lf: dirfirst bool (default on) hidden bool (default off) preview bool (default on) + reverse bool (default off) scrolloff int (default 0) tabstop int (default 8) filesep string (default ":") diff --git a/docstring.go b/docstring.go index 833f7bd..0d55be7 100644 --- a/docstring.go +++ b/docstring.go @@ -55,6 +55,7 @@ The following options can be used to customize the behavior of lf: dirfirst bool (default on) hidden bool (default off) preview bool (default on) + reverse bool (default off) scrolloff int (default 0) tabstop int (default 8) filesep string (default ":") diff --git a/eval.go b/eval.go index 355a710..c5beff6 100644 --- a/eval.go +++ b/eval.go @@ -35,6 +35,15 @@ func (e *setExpr) eval(app *app, args []string) { gOpts.preview = false case "preview!": gOpts.preview = !gOpts.preview + case "reverse": + gOpts.reverse = true + app.nav.renew(app.nav.height) + case "noreverse": + gOpts.reverse = false + app.nav.renew(app.nav.height) + case "reverse!": + gOpts.reverse = !gOpts.reverse + 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 4dc2d43..4426d7e 100644 --- a/nav.go +++ b/nav.go @@ -66,6 +66,12 @@ func getFilesSorted(path string) []*file { log.Printf("unknown sorting type: %s", gOpts.sortby) } + if gOpts.reverse { + for i, j := 0, len(fi)-1; i < j; i, j = i+1, j-1 { + fi[i], fi[j] = fi[j], fi[i] + } + } + if gOpts.dirfirst { sortFilesStable(fi, func(i, j int) bool { if fi[i].IsDir() == fi[j].IsDir() { diff --git a/opts.go b/opts.go index ccd7e85..bc291da 100644 --- a/opts.go +++ b/opts.go @@ -6,6 +6,7 @@ var gOpts struct { dirfirst bool hidden bool preview bool + reverse bool scrolloff int tabstop int filesep string @@ -24,6 +25,7 @@ func init() { gOpts.dirfirst = true gOpts.hidden = false gOpts.preview = true + gOpts.reverse = false gOpts.scrolloff = 0 gOpts.tabstop = 8 gOpts.filesep = ":"