diff --git a/complete.go b/complete.go index c48b35cd..003f055f 100644 --- a/complete.go +++ b/complete.go @@ -71,6 +71,7 @@ var ( "delete", "tag", "tag-toggle", + "keys", } gOptWords = []string{ diff --git a/doc.go b/doc.go index 86e0c421..1cd3fe98 100644 --- a/doc.go +++ b/doc.go @@ -10,7 +10,7 @@ This documentation can either be read from terminal using 'lf -doc' or online at You can also use 'doc' command (default '') 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 -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. Quick Reference @@ -78,6 +78,7 @@ The following commands are provided by lf: mark-remove (modal) (default '"') tag tag-toggle (default 't') + keys The following command line commands are provided by lf: @@ -208,6 +209,7 @@ The following additional keybindings are provided by default: map se :set sortby ext; set info map gh cd ~ map :toggle; down + map :doc Configuration @@ -471,6 +473,10 @@ You can define a new tag clearing command by combining 'tag' with 'tag-toggle' ( Tag a file with '*' or a single width character given in the argument if the file is untagged, otherwise remove the tag. + keys + +List active key bindings in the pager. + Command Line Commands This section shows information about command line commands. diff --git a/docstring.go b/docstring.go index c0e933f8..f5a87728 100644 --- a/docstring.go +++ b/docstring.go @@ -13,7 +13,8 @@ command (default '') 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 -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. Quick Reference @@ -82,6 +83,7 @@ The following commands are provided by lf: mark-remove (modal) (default '"') tag tag-toggle (default 't') + keys The following command line commands are provided by lf: @@ -213,6 +215,7 @@ The following additional keybindings are provided by default: map se :set sortby ext; set info map gh cd ~ map :toggle; down + map :doc Configuration @@ -496,6 +499,10 @@ can define a new tag clearing command by combining 'tag' with 'tag-toggle' Tag a file with '*' or a single width character given in the argument if the file is untagged, otherwise remove the tag. + keys + +List active key bindings in the pager. + Command Line Commands diff --git a/eval.go b/eval.go index af3671d1..4a6beee5 100644 --- a/eval.go +++ b/eval.go @@ -1466,6 +1466,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.nav, false) + if err != nil { + app.ui.echoerrf("keys: %s:", err) + } case "cd": path := "~" if len(e.args) > 0 { diff --git a/lf.1 b/lf.1 index 77c58d18..2a5980ef 100644 --- a/lf.1 +++ b/lf.1 @@ -26,7 +26,7 @@ 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 '') 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 @@ -93,6 +93,7 @@ The following commands are provided by lf: mark-remove (modal) (default '"') tag tag-toggle (default 't') + keys .EE .PP The following command line commands are provided by lf: @@ -235,6 +236,7 @@ The following additional keybindings are provided by default: map se :set sortby ext; set info map gh cd ~ map :toggle; down + map :doc .EE .SH CONFIGURATION Configuration files should be located at: @@ -578,6 +580,12 @@ Tag a file with '*' or a single width character given in the argument. You can d .EE .PP Tag a file with '*' or a single width character given in the argument if the file is untagged, otherwise remove the tag. +.PP +.EX + keys +.EE +.PP +List active key bindings in the pager. .SH COMMAND LINE COMMANDS This section shows information about command line commands. These should be mostly compatible with readline keybindings. A character refers to a unicode code point, a word consists of letters and digits, and a unix word consists of any non-blank characters. .PP diff --git a/os.go b/os.go index 3dd9b1f9..056280f4 100644 --- a/os.go +++ b/os.go @@ -146,10 +146,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"} diff --git a/os_windows.go b/os_windows.go index 1852c869..5884eaaa 100644 --- a/os_windows.go +++ b/os_windows.go @@ -109,10 +109,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%"}