diff --git a/doc.go b/doc.go index fc9e25c..54df2d5 100644 --- a/doc.go +++ b/doc.go @@ -250,6 +250,14 @@ A custom 'open' command can be defined to override this default. (See also 'OPENER' variable and 'Opening Files' section) + jump-prev (default '[') + +Change the current working directory to the previous jumplist item. + + jump-next (default ']') + +Change the current working directory to the next jumplist item. + top (default 'gg' and '') bottom (default 'G' and '') diff --git a/docstring.go b/docstring.go index 3999f62..9089740 100644 --- a/docstring.go +++ b/docstring.go @@ -260,6 +260,14 @@ default. (See also 'OPENER' variable and 'Opening Files' section) + jump-prev (default '[') + +Change the current working directory to the previous jumplist item. + + jump-next (default ']') + +Change the current working directory to the next jumplist item. + top (default 'gg' and '') bottom (default 'G' and '') diff --git a/eval.go b/eval.go index abd2249..597f1be 100644 --- a/eval.go +++ b/eval.go @@ -470,6 +470,7 @@ func preChdir(app *app) { } func onChdir(app *app) { + app.nav.addJumpList() if cmd, ok := gOpts.cmds["on-cd"]; ok { cmd.eval(app, nil) } @@ -884,6 +885,26 @@ func (e *callExpr) eval(app *app, args []string) { if cmd, ok := gOpts.cmds["open"]; ok { cmd.eval(app, e.args) } + case "jump-prev": + resetIncCmd(app) + preChdir(app) + for i := 0; i < e.count; i++ { + app.nav.cdJumpListPrev() + } + app.ui.loadFile(app.nav, true) + app.ui.loadFileInfo(app.nav) + restartIncCmd(app) + onChdir(app) + case "jump-next": + resetIncCmd(app) + preChdir(app) + for i := 0; i < e.count; i++ { + app.nav.cdJumpListNext() + } + app.ui.loadFile(app.nav, true) + app.ui.loadFileInfo(app.nav) + restartIncCmd(app) + onChdir(app) case "quit": app.quitChan <- struct{}{} case "top": diff --git a/lf.1 b/lf.1 index 773090f..77529c3 100644 --- a/lf.1 +++ b/lf.1 @@ -286,6 +286,18 @@ If the current file is a directory, then change the current directory to it, oth .PP (See also 'OPENER' variable and 'Opening Files' section) .PP +.EX + jump-prev (default '[') +.EE +.PP +Change the current working directory to the previous jumplist item. +.PP +.EX + jump-next (default ']') +.EE +.PP +Change the current working directory to the next jumplist item. +.PP .EX top (default 'gg' and '') bottom (default 'G' and '') diff --git a/nav.go b/nav.go index a5a5010..886cabc 100644 --- a/nav.go +++ b/nav.go @@ -364,6 +364,8 @@ type nav struct { searchPos int prevFilter []string volatilePreview bool + jumpList []string + jumpListInd int } func (nav *nav) loadDirInternal(path string) *dir { @@ -480,13 +482,46 @@ func newNav(height int) *nav { selections: make(map[string]int), selectionInd: 0, height: height, + jumpList: make([]string, 0), + jumpListInd: -1, } nav.getDirs(wd) + nav.addJumpList() return nav } +func (nav *nav) addJumpList() { + currPath := nav.currDir().path + if nav.jumpListInd >= 0 && nav.jumpListInd < len(nav.jumpList)-1 { + if nav.jumpList[nav.jumpListInd] == currPath { + // walking the jumpList + return + } + nav.jumpList = nav.jumpList[:nav.jumpListInd+1] + } + if len(nav.jumpList) == 0 || nav.jumpList[len(nav.jumpList)-1] != currPath { + nav.jumpList = append(nav.jumpList, currPath) + } + nav.jumpListInd = len(nav.jumpList) - 1 +} + +func (nav *nav) cdJumpListPrev() { + // currPath := nav.currDir().path + if nav.jumpListInd > 0 { + nav.jumpListInd -= 1 + nav.cd(nav.jumpList[nav.jumpListInd]) + } +} + +func (nav *nav) cdJumpListNext() { + if nav.jumpListInd < len(nav.jumpList)-1 { + nav.jumpListInd += 1 + nav.cd(nav.jumpList[nav.jumpListInd]) + } +} + func (nav *nav) renew() { for _, d := range nav.dirs { nav.checkDir(d) @@ -1171,7 +1206,7 @@ func (nav *nav) cd(wd string) error { } nav.getDirs(wd) - + nav.addJumpList() return nil } diff --git a/opts.go b/opts.go index 514820d..4db50b1 100644 --- a/opts.go +++ b/opts.go @@ -142,6 +142,8 @@ func init() { gOpts.keys[""] = &callExpr{"top", nil, 1} gOpts.keys["G"] = &callExpr{"bottom", nil, 1} gOpts.keys[""] = &callExpr{"bottom", nil, 1} + gOpts.keys["["] = &callExpr{"jump-prev", nil, 1} + gOpts.keys["]"] = &callExpr{"jump-next", nil, 1} gOpts.keys[""] = &listExpr{[]expr{&callExpr{"toggle", nil, 1}, &callExpr{"down", nil, 1}}, 1} gOpts.keys["v"] = &callExpr{"invert", nil, 1} gOpts.keys["u"] = &callExpr{"unselect", nil, 1}