diff --git a/comp.go b/comp.go index cb50622..1ab4a08 100644 --- a/comp.go +++ b/comp.go @@ -46,6 +46,7 @@ var ( "sync", "echo", "cd", + "select", "push", } diff --git a/doc.go b/doc.go index 0e0bcf9..0f693b4 100644 --- a/doc.go +++ b/doc.go @@ -47,6 +47,7 @@ The following commands are provided by lf without default keybindings: sync synchronizes yanked/deleted files with server echo prints its arguments to the message line cd changes working directory to its argument + select changes current file selection to its argument push simulate key pushes given in its argument The following command line commands are provided by lf with default diff --git a/docstring.go b/docstring.go index 0dc5712..0e4ddc0 100644 --- a/docstring.go +++ b/docstring.go @@ -51,6 +51,7 @@ The following commands are provided by lf without default keybindings: sync synchronizes yanked/deleted files with server echo prints its arguments to the message line cd changes working directory to its argument + select changes current file selection to its argument push simulate key pushes given in its argument The following command line commands are provided by lf with default diff --git a/eval.go b/eval.go index 4b38e9f..81741cd 100644 --- a/eval.go +++ b/eval.go @@ -387,6 +387,17 @@ func (e *callExpr) eval(app *app, args []string) { } app.ui.loadFile(app.nav) app.ui.loadFileInfo(app.nav) + case "select": + if len(e.args) != 1 { + app.ui.print("select: requires an argument") + return + } + if err := app.nav.find(e.args[0]); err != nil { + app.ui.printf("%s", err) + return + } + app.ui.loadFile(app.nav) + app.ui.loadFileInfo(app.nav) case "push": if len(e.args) > 0 { log.Println("pushing keys", e.args[0]) diff --git a/nav.go b/nav.go index 37c4071..4842ba2 100644 --- a/nav.go +++ b/nav.go @@ -260,6 +260,7 @@ func (nav *nav) getDirs(wd string) { for curr, base := wd, ""; !isRoot(base); curr, base = filepath.Dir(curr), filepath.Base(curr) { dir := nav.loadDir(curr) + dir.find(base, nav.height) dirs = append(dirs, dir) } @@ -618,6 +619,30 @@ func (nav *nav) cd(wd string) error { return nil } +func (nav *nav) find(path string) error { + lstat, err := os.Stat(path) + if err != nil { + return fmt.Errorf("select: %s", err) + } + + dir := filepath.Dir(path) + + if err := nav.cd(dir); err != nil { + return fmt.Errorf("select: %s", err) + } + + base := filepath.Base(path) + + last := nav.dirs[len(nav.dirs)-1] + if last.loading { + last.fi = append(last.fi, &file{FileInfo: lstat}) + } else { + last.find(base, nav.height) + } + + return nil +} + func match(pattern, name string) (matched bool, err error) { if gOpts.ignorecase { lpattern := strings.ToLower(pattern)