Skip to content

Commit

Permalink
Add on-init hook command (#1838)
Browse files Browse the repository at this point in the history
  • Loading branch information
joelim-work authored Nov 6, 2024
1 parent 0b51987 commit 670343a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
3 changes: 2 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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() {
Expand Down
5 changes: 5 additions & 0 deletions doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ of lf when defined:
on-cd
on-focus-gained
on-focus-lost
on-init
on-select
on-redraw
on-quit
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion lf.1
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -256,6 +256,7 @@ pre-cd
on-cd
on-focus-gained
on-focus-lost
on-init
on-select
on-redraw
on-quit
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 670343a

Please sign in to comment.