added pre-cd command (#685)
* added special pre-cd command * added documentation
This commit is contained in:
1 parent
ff0933ca03
commit
05a48ea315
4 files changed
+43
-13
No files matched your search
@@ -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.
|
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
|
Colors
|
||||||
|
|
||||||
lf tries to automatically adapt its colors to the environment.
|
lf tries to automatically adapt its colors to the environment.
|
||||||
|
|||||||
@@ -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
|
Note that all shell commands are possible but '%' and '&' are usually more
|
||||||
appropriate as '$' and '!' causes flickers and pauses respectively.
|
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
|
Colors
|
||||||
|
|
||||||
|
|||||||
@@ -453,6 +453,12 @@ func (e *cmdExpr) eval(app *app, args []string) {
|
|||||||
app.ui.loadFileInfo(app.nav)
|
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) {
|
func onChdir(app *app) {
|
||||||
if cmd, ok := gOpts.cmds["on-cd"]; ok {
|
if cmd, ok := gOpts.cmds["on-cd"]; ok {
|
||||||
cmd.eval(app, nil)
|
cmd.eval(app, nil)
|
||||||
@@ -696,6 +702,11 @@ func insert(app *app, arg string) {
|
|||||||
app.ui.echoerr("mark-load: no such mark")
|
app.ui.echoerr("mark-load: no such mark")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if wd != path {
|
||||||
|
preChdir(app)
|
||||||
|
}
|
||||||
|
|
||||||
if err := app.nav.cd(path); err != nil {
|
if err := app.nav.cd(path); err != nil {
|
||||||
app.ui.echoerrf("%s", err)
|
app.ui.echoerrf("%s", err)
|
||||||
return
|
return
|
||||||
@@ -785,6 +796,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
|
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
|
||||||
normal(app)
|
normal(app)
|
||||||
}
|
}
|
||||||
|
preChdir(app)
|
||||||
for i := 0; i < e.count; i++ {
|
for i := 0; i < e.count; i++ {
|
||||||
if err := app.nav.updir(); err != nil {
|
if err := app.nav.updir(); err != nil {
|
||||||
app.ui.echoerrf("%s", err)
|
app.ui.echoerrf("%s", err)
|
||||||
@@ -805,6 +817,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if curr.IsDir() {
|
if curr.IsDir() {
|
||||||
|
preChdir(app)
|
||||||
err := app.nav.open()
|
err := app.nav.open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.ui.echoerrf("opening directory: %s", err)
|
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)
|
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 {
|
if err := app.nav.cd(path); err != nil {
|
||||||
app.ui.echoerrf("%s", err)
|
app.ui.echoerrf("%s", err)
|
||||||
return
|
return
|
||||||
@@ -1168,12 +1191,6 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.ui.loadFile(app.nav, true)
|
app.ui.loadFile(app.nav, true)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
|
|
||||||
if !filepath.IsAbs(path) {
|
|
||||||
path = filepath.Join(wd, path)
|
|
||||||
} else {
|
|
||||||
path = filepath.Clean(path)
|
|
||||||
}
|
|
||||||
|
|
||||||
if wd != path {
|
if wd != path {
|
||||||
app.nav.marks["'"] = wd
|
app.nav.marks["'"] = wd
|
||||||
onChdir(app)
|
onChdir(app)
|
||||||
@@ -1189,6 +1206,17 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
log.Printf("getting current directory: %s", err)
|
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 {
|
if err := app.nav.sel(e.args[0]); err != nil {
|
||||||
app.ui.echoerrf("%s", err)
|
app.ui.echoerrf("%s", err)
|
||||||
return
|
return
|
||||||
@@ -1197,13 +1225,6 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.ui.loadFile(app.nav, true)
|
app.ui.loadFile(app.nav, true)
|
||||||
app.ui.loadFileInfo(app.nav)
|
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 {
|
if wd != path {
|
||||||
app.nav.marks["'"] = wd
|
app.nav.marks["'"] = wd
|
||||||
onChdir(app)
|
onChdir(app)
|
||||||
|
|||||||
@@ -1399,6 +1399,8 @@ This command runs whenever you change directory but not on startup. You can add
|
|||||||
.EE
|
.EE
|
||||||
.PP
|
.PP
|
||||||
Note that all shell commands are possible but `%` and `&` are usually more appropriate as `$` and `!` causes flickers and pauses respectively.
|
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
|
.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:
|
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
|
.PP
|
||||||
|
|||||||
Reference in new issue
Block a user