From 670343a23f77c43ddeda6dd9b9419b4bdba61c78 Mon Sep 17 00:00:00 2001 From: Joe Lim <50560759+joelim-work@users.noreply.github.com> Date: Wed, 6 Nov 2024 12:12:12 +1100 Subject: [PATCH] Add `on-init` hook command (#1838) --- client.go | 3 ++- doc.md | 5 +++++ doc.txt | 6 ++++++ eval.go | 8 ++++++++ lf.1 | 7 ++++++- 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/client.go b/client.go index 00fa1f59..ea0944d5 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 fb8d4cdb..ab0404a7 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 b1d9396e..ede9b503 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 a4631ea5..91df3268 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 452b175d..2280e198 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