Add possibility to execute commands when directory changes (on_chdir) (#291)
* Add possibility to execute commands when cwd changes (on_chdir) * Renamed function and special command on_chdir (onChdir, on-cd), support select command
This commit is contained in:
parent
6693709f36
commit
9c1836c18b
11
eval.go
11
eval.go
@ -330,6 +330,12 @@ func (e *cmdExpr) eval(app *app, args []string) {
|
|||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func onChdir(app *app) {
|
||||||
|
if cmd, ok := gOpts.cmds["on-cd"]; ok {
|
||||||
|
cmd.eval(app, nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func splitKeys(s string) (keys []string) {
|
func splitKeys(s string) (keys []string) {
|
||||||
for i := 0; i < len(s); {
|
for i := 0; i < len(s); {
|
||||||
r, w := utf8.DecodeRuneInString(s[i:])
|
r, w := utf8.DecodeRuneInString(s[i:])
|
||||||
@ -535,6 +541,7 @@ func insert(app *app, arg string) {
|
|||||||
|
|
||||||
if wd != path {
|
if wd != path {
|
||||||
app.nav.marks["'"] = wd
|
app.nav.marks["'"] = wd
|
||||||
|
onChdir(app)
|
||||||
}
|
}
|
||||||
case app.ui.cmdPrefix == "mark-remove: ":
|
case app.ui.cmdPrefix == "mark-remove: ":
|
||||||
normal(app)
|
normal(app)
|
||||||
@ -610,6 +617,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
}
|
}
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
|
onChdir(app)
|
||||||
case "open":
|
case "open":
|
||||||
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
|
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
|
||||||
normal(app)
|
normal(app)
|
||||||
@ -628,6 +636,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
}
|
}
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
|
onChdir(app)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -903,6 +912,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
|
|
||||||
if wd != path {
|
if wd != path {
|
||||||
app.nav.marks["'"] = wd
|
app.nav.marks["'"] = wd
|
||||||
|
onChdir(app)
|
||||||
}
|
}
|
||||||
case "select":
|
case "select":
|
||||||
if len(e.args) != 1 {
|
if len(e.args) != 1 {
|
||||||
@ -932,6 +942,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
|
|
||||||
if wd != path {
|
if wd != path {
|
||||||
app.nav.marks["'"] = wd
|
app.nav.marks["'"] = wd
|
||||||
|
onChdir(app)
|
||||||
}
|
}
|
||||||
case "glob-select":
|
case "glob-select":
|
||||||
if len(e.args) != 1 {
|
if len(e.args) != 1 {
|
||||||
|
Loading…
Reference in New Issue
Block a user