From 1878faa942f5690a1541209f8ae432c26f554f59 Mon Sep 17 00:00:00 2001 From: MahouShoujoMivutilde <14999778+MahouShoujoMivutilde@users.noreply.github.com> Date: Wed, 9 Apr 2025 09:37:55 +0300 Subject: [PATCH] Implement `files` query to export files in the current directory as (#1949) presented in lf (including filter/sorting) `lf -remote "query $id files"` This version updates `files` list only before running shell commands. --- app.go | 1 + doc.md | 1 + doc.txt | 1 + lf.1 | 3 ++- ui.go | 18 ++++++++++++++++++ 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/app.go b/app.go index 5c246bda..dfe1c7ba 100644 --- a/app.go +++ b/app.go @@ -552,6 +552,7 @@ func (app *app) runShell(s string, args []string, prefix string) { gState.data["cmds"] = listCmds() gState.data["jumps"] = listJumps(app.nav.jumpList, app.nav.jumpListInd) gState.data["history"] = listHistory(app.cmdHistory) + gState.data["files"] = listFilesInCurrDir(app.nav) gState.mutex.Unlock() cmd := shellCommand(s, args) diff --git a/doc.md b/doc.md index 90637399..2d4f5be3 100644 --- a/doc.md +++ b/doc.md @@ -1470,6 +1470,7 @@ The following types of information are supported: cmds list of commands created by the 'cmd' command jumps contents of the jump list, showing previously visited locations history list of previously executed commands on the command line + files list of files in the currently open directory as displayed by lf, empty if dir is still loading This is useful for scripting actions based on the internal state of lf. For example, to select a previous command using fzf and execute it: diff --git a/doc.txt b/doc.txt index 72d9f2cd..7f111a4d 100644 --- a/doc.txt +++ b/doc.txt @@ -1634,6 +1634,7 @@ The following types of information are supported: cmds list of commands created by the 'cmd' command jumps contents of the jump list, showing previously visited locations history list of previously executed commands on the command line + files list of files in the currently open directory as displayed by lf, empty if dir is still loading This is useful for scripting actions based on the internal state of lf. For example, to select a previous command using fzf and execute it: diff --git a/lf.1 b/lf.1 index 8ae32bfd..62e8071c 100644 --- a/lf.1 +++ b/lf.1 @@ -1,6 +1,6 @@ .\" Automatically generated by Pandoc 2.11.4 .\" -.TH "LF" "1" "2025-02-18" "" "DOCUMENTATION" +.TH "LF" "1" "2025-04-08" "r34-21-g3fdd991" "DOCUMENTATION" .hy .SH NAME .PP @@ -1807,6 +1807,7 @@ cmaps list of mappings created by the \[aq]cmap\[aq] command cmds list of commands created by the \[aq]cmd\[aq] command jumps contents of the jump list, showing previously visited locations history list of previously executed commands on the command line +files list of files in the currently open directory as displayed by lf, empty if dir is still loading \f[R] .fi .PP diff --git a/ui.go b/ui.go index eeae0cfa..7be740bf 100644 --- a/ui.go +++ b/ui.go @@ -1224,6 +1224,24 @@ func listMarks(marks map[string]string) string { return b.String() } +func listFilesInCurrDir(nav *nav) string { + if !nav.init { + return "" + } + dir := nav.currDir() + if dir.loading { + log.Printf("listFilesInCurrDir(): %s is still loading, `files` isn't ready for remote query", dir.path) + return "" + } + + b := new(strings.Builder) + for _, file := range dir.files { + fmt.Fprintln(b, file.path) + } + + return b.String() +} + func (ui *ui) pollEvent() tcell.Event { select { case val := <-ui.keyChan: