Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add :keys command to list current key bindings. #918

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions complete.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ var (
"mark-remove",
"tag",
"tag-toggle",
"keys",
"cmd-escape",
"cmd-complete",
"cmd-menu-complete",
Expand Down
7 changes: 7 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ You can also use 'doc' command (default '<f-1>') inside lf to view the documenta
A man page with the same content is also available in the repository at https://github.com/gokcehan/lf/blob/master/lf.1

You can run 'lf -help' to see descriptions of command line options.
The 'keys' command inside lf lists available key bindings.

# Quick Reference

The following commands are provided by lf:

quit (default 'q')
keys
up (default 'k' and '<up>')
half-up (default '<c-u>')
page-up (default '<c-b>' and '<pgup>')
Expand Down Expand Up @@ -214,6 +216,7 @@ The following additional keybindings are provided by default:
map se :set sortby ext; set info
map gh cd ~
map <space> :toggle; down
map <f-1> :doc

If the 'mouse' option is enabled, mouse buttons have the following default effects:

Expand Down Expand Up @@ -285,6 +288,10 @@ Modal commands do not take any arguments, but instead change the operation mode

Quit lf and return to the shell.

keys

List active key bindings in the pager.

up (default 'k' and '<up>')
half-up (default '<c-u>')
page-up (default '<c-b>' and '<pgup>')
Expand Down
9 changes: 8 additions & 1 deletion docstring.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -1540,6 +1540,25 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.echomsg(strings.Join(e.args, " "))
case "echoerr":
app.ui.echoerr(strings.Join(e.args, " "))
case "keys":
tempfile, err := os.CreateTemp("", "lf_bindings")
if err != nil {
app.ui.echoerrf("keys: %s:", err)
return
}
_, err = tempfile.Write(listBinds(gOpts.keys).Bytes())
tempfile.Close()

filename := tempfile.Name()
if err == nil {
app.runShell(pageFileCommand(filename), e.args, "$")
}

os.Remove(filename)
app.ui.loadFile(app, false)
if err != nil {
app.ui.echoerrf("keys: %s:", err)
}
case "cd":
path := "~"
if len(e.args) > 0 {
Expand Down
10 changes: 9 additions & 1 deletion lf.1
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ Source code can be found in the repository at https://github.com/gokcehan/lf
.PP
This documentation can either be read from terminal using 'lf -doc' or online at https://pkg.go.dev/github.com/gokcehan/lf You can also use 'doc' command (default '<f-1>') inside lf to view the documentation in a pager. A man page with the same content is also available in the repository at https://github.com/gokcehan/lf/blob/master/lf.1
.PP
You can run 'lf -help' to see descriptions of command line options.
You can run 'lf -help' to see descriptions of command line options. The 'keys' command inside lf lists available key bindings.
.SH QUICK REFERENCE
The following commands are provided by lf:
.PP
.EX
quit (default 'q')
keys
up (default 'k' and '<up>')
half-up (default '<c-u>')
page-up (default '<c-b>' and '<pgup>')
Expand Down Expand Up @@ -241,6 +242,7 @@ The following additional keybindings are provided by default:
map se :set sortby ext; set info
map gh cd ~
map <space> :toggle; down
map <f-1> :doc
.EE
.PP
If the 'mouse' option is enabled, mouse buttons have the following default effects:
Expand Down Expand Up @@ -331,6 +333,12 @@ This section shows information about builtin commands. Modal commands do not tak
.PP
Quit lf and return to the shell.
.PP
.EX
keys
.EE
.PP
List active key bindings in the pager.
.PP
.EX
up (default 'k' and '<up>')
half-up (default '<c-u>')
Expand Down
6 changes: 5 additions & 1 deletion os.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,14 @@ func shellKill(cmd *exec.Cmd) error {
return cmd.Process.Kill()
}

func pageFileCommand(filename string) string {
return fmt.Sprintf(`$PAGER "%s"`, filename)
}

func setDefaults() {
gOpts.cmds["open"] = &execExpr{"&", `$OPENER "$f"`}
gOpts.keys["e"] = &execExpr{"$", `$EDITOR "$f"`}
gOpts.keys["i"] = &execExpr{"$", `$PAGER "$f"`}
gOpts.keys["i"] = &execExpr{"$", pageFileCommand(`$f`)}
gOpts.keys["w"] = &execExpr{"$", "$SHELL"}

gOpts.cmds["doc"] = &execExpr{"$", "lf -doc | $PAGER"}
Expand Down
6 changes: 5 additions & 1 deletion os_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,14 @@ func shellKill(cmd *exec.Cmd) error {
return cmd.Process.Kill()
}

func pageFileCommand(filename string) string {
return `%PAGER% ` + fmt.Sprintf(`"%s"`, filename)
}

func setDefaults() {
gOpts.cmds["open"] = &execExpr{"&", "%OPENER% %f%"}
gOpts.keys["e"] = &execExpr{"$", "%EDITOR% %f%"}
gOpts.keys["i"] = &execExpr{"!", "%PAGER% %f%"}
gOpts.keys["i"] = &execExpr{"!", pageFileCommand("%f%")}
gOpts.keys["w"] = &execExpr{"$", "%SHELL%"}

gOpts.cmds["doc"] = &execExpr{"!", "lf -doc | %PAGER%"}
Expand Down