Add on-load command (#2010)
This commit is contained in:
1 parent
b76d2546e1
commit
ff0c7f1c96
6 files changed
+47
-3
No files matched your search
@@ -427,6 +427,7 @@ func (app *app) loop() {
|
||||
|
||||
app.watchDir(d)
|
||||
|
||||
onLoad(app, d.fileNames())
|
||||
app.ui.draw(app.nav)
|
||||
case r := <-app.nav.regChan:
|
||||
app.nav.regCache[r.path] = r
|
||||
@@ -464,6 +465,8 @@ func (app *app) loop() {
|
||||
if app.ui.msgIsStat {
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
}
|
||||
|
||||
onLoad(app, []string{f.path})
|
||||
app.ui.draw(app.nav)
|
||||
case path := <-app.nav.delChan:
|
||||
deletePathRecursive(app.nav.selections, path)
|
||||
|
||||
@@ -238,6 +238,7 @@ The following special shell commands are used to customize the behavior of lf wh
|
||||
delete
|
||||
pre-cd
|
||||
on-cd
|
||||
on-load
|
||||
on-focus-gained
|
||||
on-focus-lost
|
||||
on-init
|
||||
@@ -1143,6 +1144,11 @@ This shell command can be defined to be executed before changing a directory.
|
||||
|
||||
This shell command can be defined to be executed after changing a directory.
|
||||
|
||||
## on-load
|
||||
|
||||
This shell command can be defined to be executed after loading a directory.
|
||||
It provides the files inside the directory as arguments.
|
||||
|
||||
## on-focus-gained
|
||||
|
||||
This shell command can be defined to be executed when the terminal gains focus.
|
||||
@@ -1704,6 +1710,7 @@ 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.
|
||||
Another related command is `on-load` which gets executed when loading a directory.
|
||||
|
||||
# COLORS
|
||||
|
||||
|
||||
@@ -229,6 +229,7 @@ of lf when defined:
|
||||
delete
|
||||
pre-cd
|
||||
on-cd
|
||||
on-load
|
||||
on-focus-gained
|
||||
on-focus-lost
|
||||
on-init
|
||||
@@ -1261,6 +1262,11 @@ on-cd
|
||||
This shell command can be defined to be executed after changing a
|
||||
directory.
|
||||
|
||||
on-load
|
||||
|
||||
This shell command can be defined to be executed after loading a
|
||||
directory. It provides the files inside the directory as arguments.
|
||||
|
||||
on-focus-gained
|
||||
|
||||
This shell command can be defined to be executed when the terminal gains
|
||||
@@ -1920,7 +1926,8 @@ 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.
|
||||
the directory is actually changed. Another related command is on-load
|
||||
which gets executed when loading a directory.
|
||||
|
||||
COLORS
|
||||
|
||||
|
||||
@@ -593,6 +593,17 @@ func onChdir(app *app) {
|
||||
}
|
||||
}
|
||||
|
||||
func onLoad(app *app, files []string) {
|
||||
// prevent infinite loops
|
||||
if !gOpts.dircache {
|
||||
return
|
||||
}
|
||||
|
||||
if cmd, ok := gOpts.cmds["on-load"]; ok {
|
||||
cmd.eval(app, files)
|
||||
}
|
||||
}
|
||||
|
||||
func onFocusGained(app *app) {
|
||||
if cmd, ok := gOpts.cmds["on-focus-gained"]; ok {
|
||||
cmd.eval(app, nil)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
.\" Automatically generated by Pandoc 2.11.4
|
||||
.\"
|
||||
.TH "LF" "1" "2025-05-12" "" "DOCUMENTATION"
|
||||
.TH "LF" "1" "2025-06-19" "r35-23-gef2fb79" "DOCUMENTATION"
|
||||
.hy
|
||||
.SH NAME
|
||||
.PP
|
||||
@@ -255,6 +255,7 @@ rename
|
||||
delete
|
||||
pre-cd
|
||||
on-cd
|
||||
on-load
|
||||
on-focus-gained
|
||||
on-focus-lost
|
||||
on-init
|
||||
@@ -1266,6 +1267,11 @@ directory.
|
||||
.PP
|
||||
This shell command can be defined to be executed after changing a
|
||||
directory.
|
||||
.SS on-load
|
||||
.PP
|
||||
This shell command can be defined to be executed after loading a
|
||||
directory.
|
||||
It provides the files inside the directory as arguments.
|
||||
.SS on-focus-gained
|
||||
.PP
|
||||
This shell command can be defined to be executed when the terminal gains
|
||||
@@ -2194,6 +2200,8 @@ causes flickers and pauses respectively.
|
||||
.PP
|
||||
There is also a \f[C]pre-cd\f[R] command, that works like
|
||||
\f[C]on-cd\f[R], but is run before the directory is actually changed.
|
||||
Another related command is \f[C]on-load\f[R] which gets executed when
|
||||
loading a directory.
|
||||
.SH COLORS
|
||||
.PP
|
||||
lf tries to automatically adapt its colors to the environment.
|
||||
|
||||
@@ -43,7 +43,6 @@ type file struct {
|
||||
|
||||
func newFile(path string) *file {
|
||||
lstat, err := os.Lstat(path)
|
||||
|
||||
if err != nil {
|
||||
log.Printf("getting file information: %s", err)
|
||||
return &file{
|
||||
@@ -388,6 +387,15 @@ func (dir *dir) name() string {
|
||||
return dir.files[dir.ind].Name()
|
||||
}
|
||||
|
||||
func (d *dir) fileNames() []string {
|
||||
names := []string{}
|
||||
for _, file := range d.files {
|
||||
names = append(names, file.path)
|
||||
}
|
||||
|
||||
return names
|
||||
}
|
||||
|
||||
func (dir *dir) sel(name string, height int) {
|
||||
if len(dir.files) == 0 {
|
||||
dir.ind, dir.pos = 0, 0
|
||||
|
||||
Reference in new issue
Block a user