Skip to content

Commit

Permalink
Merge pull requests
Browse files Browse the repository at this point in the history
This mainly merges gokcehan#924 with @laktak's
gokcehan#861. This also merges in the `:keys`
command (gokcehan#918) as well as 
and some unrelated minor corrections (currently
dd5dc59).
  • Loading branch information
ilyagr committed Sep 20, 2022
4 parents abba0c2 + 9b72272 + dd5dc59 + 7d77992 commit 9ca57a5
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 57 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",
}

gOptWords = []string{
Expand Down
8 changes: 7 additions & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -208,6 +209,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 @@ -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.
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 @@ -1474,6 +1474,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 {
Expand Down
10 changes: 9 additions & 1 deletion lf.1
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -235,6 +236,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
.SH CONFIGURATION
Configuration files should be located at:
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion nav.go
Original file line number Diff line number Diff line change
Expand Up @@ -1353,14 +1353,17 @@ func (nav *nav) sync() error {
}

oldmarks := nav.marks
err = nav.readMarks()
errMarks := nav.readMarks()
for _, ch := range gOpts.tempmarks {
tmp := string(ch)
if v, e := oldmarks[tmp]; e {
nav.marks[tmp] = v
}
}
err = nav.readTags()
if errMarks != nil {
return errMarks
}
return err
}

Expand Down
6 changes: 5 additions & 1 deletion os.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
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 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
2 changes: 1 addition & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func listen(l net.Listener) {

func echoerr(c net.Conn, msg string) {
fmt.Fprintln(c, msg)
log.Printf(msg)
log.Print(msg)
}

func echoerrf(c net.Conn, format string, a ...interface{}) {
Expand Down
Loading

0 comments on commit 9ca57a5

Please sign in to comment.