Skip to content

Commit

Permalink
Add :keys command to list current key bindings.
Browse files Browse the repository at this point in the history
This outputs the result of [`listBinds`] to a temporary file
and then pass it to `$PAGER`. A bit of care is taken to remove
the temporary file and refresh lf (just in case it's showing
`/tmp`).

I haven't tested it on Windows, since `lf` doesn't seem to work
on `wine`, but I think it should work there too.

It would be a bit more elegant to pipe the output directly to
`$PAGER` without a temporary file, but that would require larger
code changes, which doesn't seem worth it at the moment.

[`listBinds`]: https://github.com/gokcehan/lf/blob/e03143299d4596bbc9bb8a2d8a1b0931e3183410/ui.go#L940
  • Loading branch information
ilyagr committed Oct 16, 2022
1 parent 654b873 commit 52f4a41
Show file tree
Hide file tree
Showing 7 changed files with 240 additions and 191 deletions.
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
132 changes: 69 additions & 63 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,74 +10,75 @@ This documentation can either be read from terminal using 'lf -doc' or online at
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
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
The following commands are provided by lf:
quit (default 'q')
up (default 'k' and '<up>')
half-up (default '<c-u>')
page-up (default '<c-b>' and '<pgup>')
scroll-up (default '<c-y>')
down (default 'j' and '<down>')
half-down (default '<c-d>')
page-down (default '<c-f>' and '<pgdn>')
scroll-down (default '<c-e>')
updir (default 'h' and '<left>')
open (default 'l' and '<right>')
jump-next (default ']')
jump-prev (default '[')
top (default 'gg' and '<home>')
bottom (default 'G' and '<end>')
high (default 'H')
middle (default 'M')
low (default 'L')
toggle
invert (default 'v')
unselect (default 'u')
glob-select
glob-unselect
calcdirsize
copy (default 'y')
cut (default 'd')
paste (default 'p')
clear (default 'c')
sync
draw
redraw (default '<c-l>')
load
reload (default '<c-r>')
echo
echomsg
echoerr
cd
select
delete (modal)
rename (modal) (default 'r')
source
push
read (modal) (default ':')
shell (modal) (default '$')
shell-pipe (modal) (default '%')
shell-wait (modal) (default '!')
shell-async (modal) (default '&')
find (modal) (default 'f')
find-back (modal) (default 'F')
find-next (default ';')
find-prev (default ',')
search (modal) (default '/')
search-back (modal) (default '?')
search-next (default 'n')
search-prev (default 'N')
filter (modal)
setfilter
mark-save (modal) (default 'm')
mark-load (modal) (default "'")
mark-remove (modal) (default '"')
tag
tag-toggle (default 't')
quit (default 'q')
keys
up (default 'k' and '<up>')
half-up (default '<c-u>')
page-up (default '<c-b>' and '<pgup>')
scroll-up (default '<c-y>')
down (default 'j' and '<down>')
half-down (default '<c-d>')
page-down (default '<c-f>' and '<pgdn>')
scroll-down (default '<c-e>')
updir (default 'h' and '<left>')
open (default 'l' and '<right>')
jump-next (default ']')
jump-prev (default '[')
top (default 'gg' and '<home>')
bottom (default 'G' and '<end>')
high (default 'H')
middle (default 'M')
low (default 'L')
toggle
invert (default 'v')
unselect (default 'u')
glob-select
glob-unselect
calcdirsize
copy (default 'y')
cut (default 'd')
paste (default 'p')
clear (default 'c')
sync
draw
redraw (default '<c-l>')
load
reload (default '<c-r>')
echo
echomsg
echoerr
cd
select
delete (modal)
rename (modal) (default 'r')
source
push
read (modal) (default ':')
shell (modal) (default '$')
shell-pipe (modal) (default '%')
shell-wait (modal) (default '!')
shell-async (modal) (default '&')
find (modal) (default 'f')
find-back (modal) (default 'F')
find-next (default ';')
find-prev (default ',')
search (modal) (default '/')
search-back (modal) (default '?')
search-next (default 'n')
search-prev (default 'N')
filter (modal)
setfilter
mark-save (modal) (default 'm')
mark-load (modal) (default "'")
mark-remove (modal) (default '"')
tag
tag-toggle (default 't')
The following command line commands are provided by lf:
Expand Down Expand Up @@ -214,6 +215,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
# Configuration
Expand Down Expand Up @@ -274,6 +276,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
133 changes: 70 additions & 63 deletions 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
Loading

0 comments on commit 52f4a41

Please sign in to comment.