summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoe Lim <50560759+joelim-work@users.noreply.github.com>2024-11-06 12:12:12 +1100
committerGitHub <noreply@github.com>2024-11-06 12:12:12 +1100
commit670343a23f77c43ddeda6dd9b9419b4bdba61c78 (patch)
tree9b43035f60976dd29c6bdbaa3b4172a98c1243c0
parent0b519870441671bda90be725ff64748d836c0684 (diff)
Add `on-init` hook command (#1838)
-rw-r--r--client.go3
-rw-r--r--doc.md5
-rw-r--r--doc.txt6
-rw-r--r--eval.go8
-rw-r--r--lf.17
5 files changed, 27 insertions, 2 deletions
diff --git a/client.go b/client.go
index 00fa1f5..ea0944d 100644
--- a/client.go
+++ b/client.go
@@ -117,7 +117,7 @@ func readExpr() <-chan expr {
ch := make(chan expr)
go func() {
- duration := 1 * time.Second
+ duration := 100 * time.Millisecond
c, err := net.Dial(gSocketProt, gSocketPath)
for err != nil {
@@ -130,6 +130,7 @@ func readExpr() <-chan expr {
fmt.Fprintf(c, "conn %d\n", gClientID)
ch <- &callExpr{"sync", nil, 1}
+ ch <- &callExpr{"on-init", nil, 1}
s := bufio.NewScanner(c)
for s.Scan() {
diff --git a/doc.md b/doc.md
index fb8d4cd..ab0404a 100644
--- a/doc.md
+++ b/doc.md
@@ -239,6 +239,7 @@ The following special shell commands are used to customize the behavior of lf wh
on-cd
on-focus-gained
on-focus-lost
+ on-init
on-select
on-redraw
on-quit
@@ -1143,6 +1144,10 @@ This shell command can be defined to be executed when the terminal gains focus.
This shell command can be defined to be executed when the terminal loses focus.
+## on-init
+
+This shell command can be defined to be executed after initializing and connecting to the server.
+
## on-select
This shell command can be defined to be executed after the selection changes.
diff --git a/doc.txt b/doc.txt
index b1d9396..ede9b50 100644
--- a/doc.txt
+++ b/doc.txt
@@ -230,6 +230,7 @@ of lf when defined:
on-cd
on-focus-gained
on-focus-lost
+ on-init
on-select
on-redraw
on-quit
@@ -1262,6 +1263,11 @@ on-focus-lost
This shell command can be defined to be executed when the terminal loses
focus.
+on-init
+
+This shell command can be defined to be executed after initializing and
+connecting to the server.
+
on-select
This shell command can be defined to be executed after the selection
diff --git a/eval.go b/eval.go
index a4631ea..91df326 100644
--- a/eval.go
+++ b/eval.go
@@ -600,6 +600,12 @@ func onFocusLost(app *app) {
}
}
+func onInit(app *app) {
+ if cmd, ok := gOpts.cmds["on-init"]; ok {
+ cmd.eval(app, nil)
+ }
+}
+
func onRedraw(app *app) {
if cmd, ok := gOpts.cmds["on-redraw"]; ok {
cmd.eval(app, nil)
@@ -1801,6 +1807,8 @@ func (e *callExpr) eval(app *app, args []string) {
onFocusGained(app)
case "on-focus-lost":
onFocusLost(app)
+ case "on-init":
+ onInit(app)
case "cmd-insert":
if len(e.args) == 0 {
return
diff --git a/lf.1 b/lf.1
index 452b175..2280e19 100644
--- a/lf.1
+++ b/lf.1
@@ -1,6 +1,6 @@
.\" Automatically generated by Pandoc 2.11.4
.\"
-.TH "LF" "1" "2024-11-01" "" "DOCUMENTATION"
+.TH "LF" "1" "2024-11-06" "" "DOCUMENTATION"
.hy
.SH NAME
.PP
@@ -256,6 +256,7 @@ pre-cd
on-cd
on-focus-gained
on-focus-lost
+on-init
on-select
on-redraw
on-quit
@@ -1262,6 +1263,10 @@ focus.
.PP
This shell command can be defined to be executed when the terminal loses
focus.
+.SS on-init
+.PP
+This shell command can be defined to be executed after initializing and
+connecting to the server.
.SS on-select
.PP
This shell command can be defined to be executed after the selection