diff --git a/doc.go b/doc.go index 028bd7e4..82658788 100644 --- a/doc.go +++ b/doc.go @@ -1256,6 +1256,9 @@ You can add an extra call to make it run on startup as well: Note that all shell commands are possible but `%` and `&` are usually more appropriate as `$` and `!` causes flickers and pauses respectively. +There is also a 'pre-cd' command, that works like 'on-cd', but is run before the directory is actually changed. +It is generally a bad idea, to put movement commands (like 'up' / 'top' etc.) here. + Colors lf tries to automatically adapt its colors to the environment. diff --git a/docstring.go b/docstring.go index 18efdeff..8fbe2edc 100644 --- a/docstring.go +++ b/docstring.go @@ -1407,6 +1407,10 @@ add an extra call to make it run on startup as well: Note that all shell commands are possible but '%' and '&' are usually more appropriate as '$' and '!' causes flickers and pauses respectively. +There is also a 'pre-cd' command, that works like 'on-cd', but is run before +the directory is actually changed. It is generally a bad idea, to put +movement commands (like 'up' / 'top' etc.) here. + Colors diff --git a/eval.go b/eval.go index 0d55bfd3..6e32d7a6 100644 --- a/eval.go +++ b/eval.go @@ -453,6 +453,12 @@ func (e *cmdExpr) eval(app *app, args []string) { app.ui.loadFileInfo(app.nav) } +func preChdir(app *app) { + if cmd, ok := gOpts.cmds["pre-cd"]; ok { + cmd.eval(app, nil) + } +} + func onChdir(app *app) { if cmd, ok := gOpts.cmds["on-cd"]; ok { cmd.eval(app, nil) @@ -696,6 +702,11 @@ func insert(app *app, arg string) { app.ui.echoerr("mark-load: no such mark") return } + + if wd != path { + preChdir(app) + } + if err := app.nav.cd(path); err != nil { app.ui.echoerrf("%s", err) return @@ -785,6 +796,7 @@ func (e *callExpr) eval(app *app, args []string) { if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" { normal(app) } + preChdir(app) for i := 0; i < e.count; i++ { if err := app.nav.updir(); err != nil { app.ui.echoerrf("%s", err) @@ -805,6 +817,7 @@ func (e *callExpr) eval(app *app, args []string) { } if curr.IsDir() { + preChdir(app) err := app.nav.open() if err != nil { app.ui.echoerrf("opening directory: %s", err) @@ -1160,6 +1173,16 @@ func (e *callExpr) eval(app *app, args []string) { log.Printf("getting current directory: %s", err) } + if !filepath.IsAbs(path) { + path = filepath.Join(wd, path) + } else { + path = filepath.Clean(path) + } + + if wd != path { + preChdir(app) + } + if err := app.nav.cd(path); err != nil { app.ui.echoerrf("%s", err) return @@ -1168,12 +1191,6 @@ func (e *callExpr) eval(app *app, args []string) { app.ui.loadFile(app.nav, true) app.ui.loadFileInfo(app.nav) - if !filepath.IsAbs(path) { - path = filepath.Join(wd, path) - } else { - path = filepath.Clean(path) - } - if wd != path { app.nav.marks["'"] = wd onChdir(app) @@ -1189,6 +1206,17 @@ func (e *callExpr) eval(app *app, args []string) { log.Printf("getting current directory: %s", err) } + path := filepath.Dir(e.args[0]) + if !filepath.IsAbs(path) { + path = filepath.Join(wd, path) + } else { + path = filepath.Clean(path) + } + + if wd != path { + preChdir(app) + } + if err := app.nav.sel(e.args[0]); err != nil { app.ui.echoerrf("%s", err) return @@ -1197,13 +1225,6 @@ func (e *callExpr) eval(app *app, args []string) { app.ui.loadFile(app.nav, true) app.ui.loadFileInfo(app.nav) - path := filepath.Dir(e.args[0]) - if !filepath.IsAbs(path) { - path = filepath.Join(wd, path) - } else { - path = filepath.Clean(path) - } - if wd != path { app.nav.marks["'"] = wd onChdir(app) diff --git a/lf.1 b/lf.1 index c1d67398..0deaf780 100644 --- a/lf.1 +++ b/lf.1 @@ -1399,6 +1399,8 @@ This command runs whenever you change directory but not on startup. You can add .EE .PP Note that all shell commands are possible but `%` and `&` are usually more appropriate as `$` and `!` causes flickers and pauses respectively. +.PP +There is also a 'pre-cd' command, that works like 'on-cd', but is run before the directory is actually changed. It is generally a bad idea, to put movement commands (like 'up' / 'top' etc.) here. .SH COLORS lf tries to automatically adapt its colors to the environment. It starts with a default colorscheme and updates colors using values of existing environment variables possibly by overwriting its previous values. Colors are set in the following order: .PP